Creates and spawns an isolate that shares the same code as the current isolate.
The argument entryPoint
specifies the entry point of the spawned
isolate. It must be a top-level function or a static method that
takes one argument - that is, one-parameter functions that can be
compile-time constant function values.
It is not allowed to pass the value of function expressions or an instance
method extracted from an object.
The entry-point function is invoked with the initial message
.
Usually the initial message
contains a SendPort so
that the spawner and spawnee can communicate with each other.
If the paused
parameter is set to true
,
the isolate will start up in a paused state,
as if by an initial call of isolate.pause(isolate.pauseCapability)
.
To resume the isolate, call isolate.resume(isolate.pauseCapability)
.
If the errorAreFatal
, onExit
and/or onError
parameters are provided,
the isolate will act as if, respectively, setErrorsFatal,
addOnExitListener and addErrorListener were called with the
corresponding parameter and was processed before the isolate starts
running.
You can also call the setErrorsFatal, addOnExitListener and
addErrorListener methods on the returned isolate, but unless the
isolate was started as paused
, it may already have terminated
before those methods can complete.
Returns a future that will complete with an Isolate instance if the spawning succeeded. It will complete with an error otherwise.
Source
external static Future<Isolate> spawn(void entryPoint(message), var message,
{ bool paused: false,
bool errorsAreFatal,
SendPort onExit,
SendPort onError });