shutdown method

Future<void> shutdown()

Shuts the server down. Returns a Future that completes when the server is shut down.

Implementation

Future<void> shutdown() async {
  await _httpServer?.close();
  var webSockets = _webSockets.values.toList();
  List<Future<void>> webSocketCompletions = [];
  for (var (webSocketCompletion, webSocket) in webSockets) {
    webSocketCompletions.add(webSocketCompletion);
    await webSocket.close();
  }

  // Wait for all WebSockets to close.
  await Future.wait(webSocketCompletions);

  _running = false;
}