An isolated Dart execution context.
All Dart code runs in an isolate, and code can access classes and values only from the same isolate. Different isolates can communicate by sending values through ports (see ReceivePort, SendPort).
An Isolate
object is a reference to an isolate, usually different from
the current isolate.
It represents, and can be used control, the other isolate.
When spawning a new isolate, the spawning isolate receives an Isolate
object representing the new isolate when the spawn operation succeeds.
Isolates run code in its own event loop, and each event may run smaller tasks in a nested microtask queue.
An Isolate
object allows other isolates to control the event loop
of the isolate that it represents, and to inspect the isolate,
for example by pausing the isolate or by getting events when the isolate
has an uncaught error.
The controlPort gives access to controlling the isolate, and the
pauseCapability and terminateCapability guard access to some control
operations.
The Isolate
object provided by a spawn operation will have the
control port and capabilities needed to control the isolate.
New isolates objects can be created without some of these capabilities
if necessary.
An Isolate
object cannot be sent over a SendPort
, but the control port
and capabilities can be sent, and can be used to create a new functioning
Isolate
object in the receiving port's isolate.
Constants
- BEFORE_NEXT_EVENT → int
-
Argument to
ping
andkill
: Ask for action before the next event.1
- IMMEDIATE → int
-
Argument to
ping
andkill
: Ask for immediate action.0
Static Properties
- current → Isolate
-
Return the current
Isolate
.read-only - packageConfig → Future<Uri>
-
Returns the package root of the current isolate, if any.
read-only - packageRoot → Future<Uri>
-
Returns the package root of the current isolate, if any.
read-only
Static Methods
-
resolvePackageUri(
Uri packageUri) → Future<Uri> -
Maps a package: URI to a non-package Uri.
-
spawn(
void entryPoint(message), message, { bool paused: false, bool errorsAreFatal, SendPort onExit, SendPort onError }) → Future<Isolate> -
Creates and spawns an isolate that shares the same code as the current isolate.
-
spawnUri(
Uri uri, List<String> args, message, { bool paused: false, SendPort onExit, SendPort onError, bool errorsAreFatal, bool checked, Map<String, String> environment, Uri packageRoot, Uri packageConfig, bool automaticPackageResolution: false }) → Future<Isolate> -
Creates and spawns an isolate that runs the code from the library with the specified URI.
Constructors
- Isolate(SendPort controlPort, { Capability pauseCapability, Capability terminateCapability })
-
Create a new Isolate object with a restricted set of capabilities.
Properties
- controlPort → SendPort
-
Control port used to send control messages to the isolate.
read-only - errors → Stream
-
Returns a broadcast stream of uncaught errors from the isolate.
read-only - hashCode → int
-
Get a hash code for this object.
read-only, inherited - pauseCapability → Capability
-
Capability granting the ability to pause the isolate.
read-only - runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited - terminateCapability → Capability
-
Capability granting the ability to terminate the isolate.
read-only
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
addErrorListener(
SendPort port) → void -
Requests that uncaught errors of the isolate are sent back to
port
. -
addOnExitListener(
SendPort responsePort, { Object response }) → void -
Asks the isolate to send
response
onresponsePort
when it terminates. -
kill(
{int priority: BEFORE_NEXT_EVENT }) → void -
Requests the isolate to shut down.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
pause(
[Capability resumeCapability ]) → Capability -
Requests the isolate to pause.
-
ping(
SendPort responsePort, { Object response, int priority: IMMEDIATE }) → void -
Request that the isolate send
response
on theresponsePort
. -
removeErrorListener(
SendPort port) → void -
Stop listening for uncaught errors through
port
. -
removeOnExitListener(
SendPort responsePort) → void -
Stop listening on exit messages from the isolate.
-
resume(
Capability resumeCapability) → void -
Resumes a paused isolate.
-
setErrorsFatal(
bool errorsAreFatal) → void -
Set whether uncaught errors will terminate the isolate.
-
toString(
) → String -
Returns a string representation of this object.
inherited