Skip to content

Commit d7b7ff8

Browse files
authored
Simplify waiting during close (dart-archive/http2#105)
Use a for loop element in a list literal to collect all the futures rather than a nested `Future.wait` to concatenate the single server close with many connection closes. Refactor from `return` to `=>` at both levels since this reads more nicely if it looks declarative.
1 parent 3376ba0 commit d7b7ff8

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

pkgs/http2/lib/multiprotocol_server.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,11 @@ class MultiProtocolHttpServer {
9393
/// Closes this [MultiProtocolHttpServer].
9494
///
9595
/// Completes once everything has been successfully shut down.
96-
Future close({bool force = false}) {
97-
return _serverSocket.close().whenComplete(() async {
98-
var done1 = _http11Server.close(force: force);
99-
Future done2 = Future.wait(
100-
_http2Connections.map((c) => force ? c.terminate() : c.finish()));
101-
await Future.wait([done1, done2]);
102-
});
103-
}
96+
Future close({bool force = false}) =>
97+
_serverSocket.close().whenComplete(() => Future.wait([
98+
_http11Server.close(force: force),
99+
for (var c in _http2Connections) force ? c.terminate() : c.finish()
100+
]));
104101
}
105102

106103
/// An internal helper class.

0 commit comments

Comments
 (0)