stop method

Future<void> stop()

Stops the node: sends a goodbye, closes the connection, and ends the loop.

Implementation

Future<void> stop() async {
  if (_stopped) return;
  _stopped = true;
  final typed = _typed;
  if (typed != null && typed.isOpen) {
    typed.send(const NodeGoodbye('shutdown'));
    await typed.close();
  }
  await _loop;
  _loop = null;
  if (!_states.isClosed) await _states.close();
}