addOnExitListener method

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

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. To avoid this, start the isolate paused, add the listener, then resume it.