stopServing method

Future<void> stopServing(
  1. Duration timeout
)

The first part of stopAll: every isolate that serves stops gracefully. The isolates are not killed.

Implementation

Future<void> stopServing(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 provider shutdowns
          .timeout(timeout + const Duration(seconds: 1), onTimeout: _no)
          .whenComplete(reply.close),
    );
  }
  await Future.wait(waits);
}