kill method

Future<void> kill({
  1. Duration timeout = const Duration(seconds: 1),
})

Kills the isolate.

Starts by calling close, but if that doesn't cause the isolate to shut down in a timely manner, as given by timeout, it follows up with Isolate.kill, with increasing urgency if necessary.

If timeout is a zero duration, it goes directly to the most urgent kill.

If the isolate is already dead, the returned future will not complete. If that may be the case, use Future.timeout on the returned future to take extra action after a while. Example:

var f = isolate.kill();
f.then((_) => print("Dead")
 .timeout(new Duration(...), onTimeout: () => print("No response"));

Implementation

Future<void> kill({Duration timeout = const Duration(seconds: 1)}) {
  final onExit = singleResponseFuture(isolate.addOnExitListener);
  if (Duration.zero == timeout) {
    isolate.kill(priority: Isolate.immediate);
    return onExit;
  } else {
    // Try a more gentle shutdown sequence.
    _commandPort.send(list2(_shutdown, null));
    return onExit.timeout(timeout, onTimeout: () {
      isolate.kill(priority: Isolate.immediate);
      return onExit;
    });
  }
}