From 759363cd81ce66755430310831184b8a222bd20c Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 19 Jun 2024 12:22:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Reorg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dio/lib/src/adapters/io_adapter.dart | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dio/lib/src/adapters/io_adapter.dart b/dio/lib/src/adapters/io_adapter.dart index d69dfc36f..62837e140 100644 --- a/dio/lib/src/adapters/io_adapter.dart +++ b/dio/lib/src/adapters/io_adapter.dart @@ -75,20 +75,23 @@ class IOHttpClientAdapter implements HttpClientAdapter { ); } final operation = CancelableOperation.fromFuture( - _fetch( - options, - requestStream, - cancelFuture, - ), + _fetch(options, requestStream, cancelFuture), ); + if (cancelFuture != null) { cancelFutureOperationPool.putIfAbsent(cancelFuture, () => {}); - cancelFutureOperationPool[cancelFuture]!.add(operation); + cancelFutureRequestPool.putIfAbsent(cancelFuture, () => {}); + cancelFuture.whenComplete(() { cancelFutureOperationPool[cancelFuture]?.forEach((e) => e.cancel()); cancelFutureOperationPool.remove(cancelFuture); + cancelFutureRequestPool[cancelFuture]?.forEach((e) => e.abort()); + cancelFutureRequestPool.remove(cancelFuture); }); + + cancelFutureOperationPool[cancelFuture]!.add(operation); } + return operation.value.whenComplete( () => cancelFutureOperationPool[cancelFuture]?.remove(operation), ); @@ -119,12 +122,7 @@ class IOHttpClientAdapter implements HttpClientAdapter { } if (cancelFuture != null) { - cancelFutureRequestPool.putIfAbsent(cancelFuture, () => {}); cancelFutureRequestPool[cancelFuture]!.add(request); - cancelFuture.whenComplete(() { - cancelFutureRequestPool[cancelFuture]?.forEach((e) => e.abort()); - cancelFutureRequestPool.remove(cancelFuture); - }); } // Set Headers