dispose static method

Future<void> dispose()

Stop the worker process and clean up listeners.

Implementation

static Future<void> dispose() async {
  _initialized = false;
  await _stdoutBytesSub?.cancel();
  await _stderrSub?.cancel();
  _stdoutBytesSub = null;
  _stderrSub = null;
  final process = _process;
  _process = null;
  if (process != null) {
    unawaited(process.stdin.close());
    process.kill(ProcessSignal.sigterm);
    unawaited(process.exitCode);
  }
  _stdoutBuffer.clear();
  _expectedFrameLength = null;
  _pending.clear();
  _handshake = null;
  _nextId = 0;
}