stopAll method
Stop every isolate gracefully: each stops taking connections, lets
open requests finish (up to timeout) and runs its DoxShutdown
services. Isolates still busy after that are killed.
Implementation
Future<void> stopAll(Duration timeout) async {
_stopped = true;
List<Future<void>> waits = <Future<void>>[];
for (SendPort port in _sendPorts.values) {
ReceivePort reply = ReceivePort();
port.send(reply.sendPort);
waits.add(
reply.first
// ponytail: one extra second for the DoxShutdown services
.timeout(timeout + const Duration(seconds: 1), onTimeout: _no)
.whenComplete(reply.close),
);
}
await Future.wait(waits);
killAll();
}