stop method
Stops the process.
Completes exitCode with exitCode and returns true, or returns
false if the isolate had already finished (or another stop is in
progress).
Implementation
Future<bool> stop(int exitCode, {String? reason}) async {
if (_isolateCompleter.isCompleted || _stopping) {
await _cancelSignalListeners();
return false;
}
_stopping = true;
await _cancelSignalListeners();
// The isolate may have exited while the listeners were cancelled.
if (_isolateCompleter.isCompleted) {
return false;
}
final onStop = _onStop;
if (onStop != null) {
await onStop(reason ?? 'Terminated normally.');
}
if (stopByKill) {
isolate.kill();
}
if (!_isolateCompleter.isCompleted) {
_isolateCompleter.complete(exitCode);
}
return true;
}