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();
  }

  // The registry closes what it holds open, and a durable one writes what
  // is still waiting first. Walking `documentIds` here instead would read
  // every document on disk back into memory just to dispose it, and would
  // leave the registry holding disposed documents.
  //
  // Before the event controller, so a failure to write still reaches a
  // listener.
  try {
    await _serverRegistry.close();
  } catch (e) {
    _addServerEvent(
      ServerEvent(
        type: ServerEventType.error,
        message: 'Error closing the document registry: $e',
      ),
    );
  }

  unawaited(_serverEventController.close());
}