closeGracefully method
The close() of dart:io does not wait for the open requests: it
waits here, until no connection has a request. WebSockets get 1001.
Implementation
// ponytail: polls every 20 ms, only on a stop. A server that never
// reports 0 keeps it polling until the isolate exits after the stop.
@override
Future<void> closeGracefully(HttpServer server) async {
await server.close();
for (WebSocket ws in _sockets.toList()) {
unawaited(ws.close(WebSocketStatus.goingAway));
}
while (_active(server) > 0) {
await Future<void>.delayed(const Duration(milliseconds: 20));
}
}