Isolate classfinal
An isolated Dart execution context.
All Dart code runs in an isolate, and code can access classes and valuesonly from the same isolate. Different isolates can communicate by sendingvalues through ports (seeReceivePort,SendPort).
AnIsolate object is a reference to an isolate, usually different fromthe current isolate.It represents, and can be used to control, the other isolate.
When spawning a new isolate, the spawning isolate receives anIsolateobject representing the new isolate when the spawn operation succeeds.
Isolates run code in its own event loop, and each event may run smaller tasksin a nested microtask queue.
AnIsolate object allows other isolates to control the event loopof the isolate that it represents, and to inspect the isolate,for example by pausing the isolate or by getting events when the isolatehas an uncaught error.
ThecontrolPort identifies and gives access to controlling the isolate,and thepauseCapability andterminateCapability guard accessto some control operations.For example, callingpause on anIsolate object created without apauseCapability, has no effect.
TheIsolate object provided by a spawn operation will have thecontrol port and capabilities needed to control the isolate.New isolate objects can be created without some of these capabilitiesif necessary, using theIsolate.new constructor.
AnIsolate object cannot be sent over aSendPort, but the control portand capabilities can be sent, and can be used to create a new functioningIsolate object in the receiving port's isolate.
Constructors
- Isolate(SendPortcontrolPort, {Capability?pauseCapability,Capability?terminateCapability})
- Creates a newIsolate object with a restricted set of capabilities.
Properties
- controlPort→SendPort
- Control port used to send control messages to the isolate.final
- debugName→String?
- The name of theIsolate displayed for debug purposes.no setter
- errors→Stream
- Returns a broadcast stream of uncaught errors from the isolate.no setter
- hashCode→int
- The hash code for this object.no setterinherited
- pauseCapability→Capability?
- Capability granting the ability to pause the isolate.final
- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
- terminateCapability→Capability?
- Capability granting the ability to terminate the isolate.final
Methods
- addErrorListener(
SendPortport)→ void - Requests that uncaught errors of the isolate are sent back to
port. - addOnExitListener(
SendPortresponsePort, {Object?response})→ void - Requests an exit message on
responsePortwhen the isolate terminates. - kill(
{intpriority =beforeNextEvent})→ void - Requests the isolate to shut down.
- noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- pause(
[Capability?resumeCapability])→Capability - Requests the isolate to pause.
- ping(
SendPortresponsePort, {Object?response,intpriority =immediate})→ void - Requests that the isolate send
responseon theresponsePort. - removeErrorListener(
SendPortport)→ void - Stops listening for uncaught errors from the isolate.
- removeOnExitListener(
SendPortresponsePort)→ void - Stops listening for exit messages from the isolate.
- resume(
CapabilityresumeCapability)→ void - Resumes a paused isolate.
- setErrorsFatal(
boolerrorsAreFatal)→ void - Sets whether uncaught errors will terminate the isolate.
- toString(
)→String - A string representation of this object.inherited
Operators
- operator ==(
Objectother)→bool - The equality operator.inherited
Static Properties
- current→Isolate
- AnIsolate object representing the current isolate.no setter
- packageConfig→Future<
Uri?> - The location of the package configuration file of the current isolate.no setter
- packageConfigSync→Uri?
- The location of the package configuration file of the current isolate.no setter
Static Methods
- exit(
[SendPort?finalMessagePort,Object?message])→ Never - Terminates the current isolate synchronously.
- resolvePackageUri(
UripackageUri)→Future< Uri?> - Resolves a
package:URI to its actual location. - resolvePackageUriSync(
UripackageUri)→Uri? - Resolves a
package:URI to its actual location. - run<
R> (FutureOr< R> computation(), {String?debugName})→Future<R> - Runs
computationin a new isolate and returns the result. - spawn<
T> (voidentryPoint(Tmessage),Tmessage, {boolpaused =false,boolerrorsAreFatal =true,SendPort?onExit,SendPort?onError,String?debugName})→Future< Isolate> - Spawns an isolate that shares the same code as the current isolate.
- spawnUri(
Uriuri,List< String> args,dynamicmessage, {boolpaused =false,SendPort?onExit,SendPort?onError,boolerrorsAreFatal =true,bool?checked,Map<String,String> ?environment,Uri?packageRoot,Uri?packageConfig,boolautomaticPackageResolution =false,String?debugName})→Future<Isolate> - Spawns an isolate running the script file specified by
uri.
Constants
- beforeNextEvent→ constint
- Argument to
pingandkill: Ask for action before the next event. - immediate→ constint
- Argument to
pingandkill: Ask for immediate action.