exit method Null safety

Never exit(
  1. [SendPort? finalMessagePort,
  2. Object? message]
)

Terminates the current isolate synchronously.

This operations is potentially dangerous and should be used judiciously. The isolate stops operating immediately. It throws if optional message does not adhere to the limitation on what can be send from one isolate to another. It also throws if a finalMessagePort is associated with an isolate spawned outside of current isolate group, spawned via spawnUri.

If successful, a call to this method does not return. Pending finally blocks are not executed, control flow will not go back to the event loop, scheduled asynchronous asks will never run, and even pending isolate control commands may be ignored. (The isolate will send messages to ports already registered using Isolate.addOnExitListener, but no further Dart code will run in the isolate.)

If finalMessagePort is provided, and the message can be sent through it, then the message is sent through that port as the final operation of the current isolate. The isolate terminates immediately after that SendPort.send call returns.

(If the port is a native port, one provided by ReceivePort.sendPort or RawReceivePort.sendPort, the system may be able to send this final message more efficiently than normal port communication between live isolates.)

Implementation

external static Never exit([SendPort? finalMessagePort, Object? message]);