dispose method

void dispose({
  1. bool immediate = false,
})

Responsible for killing the isolate and close the main thread port

The shutdown is performed at different times depending on the priority:

  • immediate = true: The isolate shuts down as soon as possible. Control messages are handled in order, so all previously sent control events from this isolate will all have been processed. The shutdown should happen no later than if sent with immediate = false. It may happen earlier if the system has a way to shut down cleanly at an earlier time, even during the execution of another event.
  • immediate = false: The shutdown is scheduled for the next time control returns to the event loop of the receiving isolate, after the current event, and any already scheduled control events, are completed.

Implementation

void dispose({bool immediate = false}) {
  _mainReceivePort.close();
  _isolate.kill(
    priority: immediate ? Isolate.immediate : Isolate.beforeNextEvent,
  );
}