dispose method

  1. @override
Future<void> dispose()
override

Dispose the server

Implementation

@override
Future<void> dispose() async {
  await stop();

  for (final plugin in plugins) {
    plugin.dispose();
  }

  // Before the event controller, so a failure to release what the host
  // holds — a registry with writes still waiting, say — still reaches a
  // listener.
  try {
    await onDispose();
  } catch (e) {
    addServerEvent(
      ServerEvent(
        type: ServerEventType.error,
        message: 'Error disposing the host: $e',
      ),
    );
  }

  _state = SessionHostState.disposed;

  unawaited(_serverEventController.close());
}