shutdown method
Graceful stop: no new connections, open requests get timeout to
finish. Then every connection is closed.
Implementation
Future<void> shutdown(Duration timeout) async {
StrictMode.stopWatchdog();
// from now on `reloadCertificate` throws a StateError
_native = null;
List<NativeHttpServer> all = _open;
_open = <NativeHttpServer>[];
try {
// completes when the open requests are done. WebSockets get 1001.
await Future.wait(<Future<void>>[
for (HttpServer s in all) s.close().then(_ignore),
]).timeout(timeout, onTimeout: _nothingList);
for (HttpServer s in all) {
await s.close(force: true);
}
} finally {
_closed();
}
}