Skip to content

Commit

Permalink
⚡️ Sync implementation details
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Jun 19, 2024
1 parent 759363c commit 9a29b3f
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions plugins/http2_adapter/lib/src/http2_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,42 @@ class Http2Adapter implements HttpClientAdapter {
RequestOptions options,
Stream<Uint8List>? requestStream,
Future<void>? cancelFuture,
) async {
) {
// Recursive fetching.
final redirects = <RedirectRecord>[];
try {
final operation = CancelableOperation.fromFuture(
_fetch(options, requestStream, cancelFuture, redirects),
);
final operation = CancelableOperation.fromFuture(
_fetch(options, requestStream, cancelFuture, redirects),
);

if (cancelFuture != null) {
cancelFutureOperationPool.putIfAbsent(cancelFuture, () => {});
cancelFutureRequestPool.putIfAbsent(cancelFuture, () => {});
if (cancelFuture != null) {
cancelFutureOperationPool.putIfAbsent(cancelFuture, () => {});
cancelFutureRequestPool.putIfAbsent(cancelFuture, () => {});

cancelFuture.whenComplete(() {
cancelFutureOperationPool[cancelFuture]?.forEach((e) => e.cancel());
cancelFutureOperationPool.remove(cancelFuture);
cancelFutureRequestPool[cancelFuture]
?.forEach((e) => e.outgoingMessages.close());
cancelFutureRequestPool.remove(cancelFuture);
});
cancelFuture.whenComplete(() {
cancelFutureOperationPool[cancelFuture]?.forEach((e) => e.cancel());
cancelFutureOperationPool.remove(cancelFuture);
cancelFutureRequestPool[cancelFuture]
?.forEach((e) => e.outgoingMessages.close());
cancelFutureRequestPool.remove(cancelFuture);
});

cancelFutureOperationPool[cancelFuture]!.add(operation);
}
cancelFutureOperationPool[cancelFuture]!.add(operation);
}

return operation.value.whenComplete(
() => cancelFutureOperationPool[cancelFuture]?.remove(operation),
);
return operation.value.whenComplete(
() => cancelFutureOperationPool[cancelFuture]?.remove(operation),
);
}

Future<ResponseBody> _fetch(
RequestOptions options,
Stream<Uint8List>? requestStream,
Future<void>? cancelFuture,
List<RedirectRecord> redirects,
) async {
late final ClientTransportConnection transport;
try {
transport = await connectionManager.getConnection(options);
} on DioH2NotSupportedException catch (e) {
// Fallback to use the callback
// or to another adapter (typically IOHttpClientAdapter)
Expand Down Expand Up @@ -105,15 +115,7 @@ class Http2Adapter implements HttpClientAdapter {
error: e,
);
}
}

Future<ResponseBody> _fetch(
RequestOptions options,
Stream<Uint8List>? requestStream,
Future<void>? cancelFuture,
List<RedirectRecord> redirects,
) async {
final transport = await connectionManager.getConnection(options);
final uri = options.uri;
String path = uri.path;
const excludeMethods = ['PUT', 'POST', 'PATCH'];
Expand Down

0 comments on commit 9a29b3f

Please sign in to comment.