stop method

  1. @override
Future<int> stop({
  1. Duration? timeLimit,
})

Attempt to gracefully shutdown the server. If that fails, then kill the process.

Implementation

@override
Future<int> stop({Duration? timeLimit}) async {
  timeLimit ??= const Duration(seconds: 5);

  final process = _process;
  if (process == null) {
    // Process already exited
    return -1;
  }

  final future = send(SERVER_REQUEST_SHUTDOWN, null);
  _process = null;
  await future
      // fall through to wait for exit
      .timeout(timeLimit, onTimeout: () {
    return {};
  }).whenComplete(() async {
    await _stderrSubscription?.cancel();
    _stderrSubscription = null;
    await _stdoutSubscription?.cancel();
    _stdoutSubscription = null;
  });
  return process.exitCode.timeout(
    timeLimit,
    onTimeout: () {
      listener?.killingServerProcess('server failed to exit');
      process.kill();
      return process.exitCode;
    },
  );
}