void addOnExitListener(SendPort responsePort, {Object response})

Asks the isolate to send response on responsePort when it terminates.

The isolate will send a response message on responsePort as the last thing before it terminates. It will run no further code after the message has been sent.

Adding the same port more than once will only cause it to receive one message, using the last response value that was added.

If the isolate is already dead, no message will be sent. If response cannot be sent to the isolate, then the request is ignored. It is recommended to only use simple values that can be sent to all isolates, like null, booleans, numbers or strings.

Since isolates run concurrently, it's possible for it to exit before the exit listener is established, and in that case no response will be sent on responsePort. To avoid this, either use the corresponding parameter to the spawn function, or start the isolate paused, add the listener and then resume the isolate.

Source

/* TODO(lrn): Can we do better? Can the system recognize this message and
 * send a reply if the receiving isolate is dead?
 */
external void addOnExitListener(SendPort responsePort, {Object response});