stop method

Future stop({
  1. bool force = false,
})

Stops the Web server.

Stops this server from listing for new connections.

This method is rarely used, since most Web servers are designed to run forever. But it can be used to implement a server shutdown feature.

The returned future completes when the server is stopped.

Any sessions are terminated.

If force is true, active connections will be closed immediately.

Implementation

Future stop({bool force = false}) async {
  _logServer.finer('stop: ${_allSessions.length} sessions, force=$force');

  if (_allSessions.isNotEmpty) {
    // Terminate all sessions
    // First copy values to a list, because calling [terminate] will change
    // the Map so simply iterating over [_allSessions.values] will not work.
    final sList = _allSessions.values.toList(growable: false);
    for (var s in sList) {
      await s.terminate();
    }
  }

  final s = _svr;
  if (s != null) {
    await s.close(force: force); // stop the HttpServer
  }

  _logServer.finer('stop: closed');
}