description

# Isolate class final

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 to 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 identifies and gives access to controlling the isolate, and the pauseCapability and terminateCapability guard access to some control operations. For example, calling pause on an `Isolate` object created without a pauseCapability, has no effect.

The `Isolate` object provided by a spawn operation will have the control port and capabilities needed to control the isolate. New isolate objects can be created without some of these capabilities if necessary, using the Isolate.new constructor.

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.

## Constructors

Isolate(SendPort controlPort, {Capability? pauseCapability, Capability? terminateCapability})
  Creates a new Isolate 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 the Isolate 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 setter inherited
isPinnedToCurrentThread → bool
  Whether the isolate is pinned to the current OS thread.
  no setter
onEvent ← void Function(Isolate)
  Event notify callback for the isolate.
  no getter
pauseCapability → Capability?
  Capability granting the ability to pause the isolate.
  final
runtimeType → Type
  A representation of the runtime type of the object.
  no setter inherited
terminateCapability → Capability?
  Capability granting the ability to terminate the isolate.
  final

## Methods

addErrorListener(SendPort port) → void
  Requests that uncaught errors of the isolate are sent back to `port`.
addOnExitListener(SendPort responsePort, {Object? response}) → void
  Requests an exit message on `responsePort` when the isolate terminates.
handleEvent() → void
  Handle at most one pending event for the isolate.
kill({int priority = beforeNextEvent}) → void
  Requests the isolate to shut down.
noSuchMethod(Invocation invocation) → dynamic
  Invoked when a nonexistent method or property is accessed.
  inherited
pause([Capability? resumeCapability]) → Capability
  Requests the isolate to pause.
ping(SendPort responsePort, {Object? response, int priority = immediate}) → void
  Requests that the isolate send `response` on the `responsePort`.
removeErrorListener(SendPort port) → void
  Stops listening for uncaught errors from the isolate.
removeOnExitListener(SendPort responsePort) → void
  Stops listening for exit messages from the isolate.
resume(Capability resumeCapability) → void
  Resumes a paused isolate.
runEventLoopSync() → void
  Run event loop for the target isolate synchronously on the current thread.
runSync<R>(R f()) → R
  Execute the given function in the context of the given isolate.
setErrorsFatal(bool errorsAreFatal) → void
  Sets whether uncaught errors will terminate the isolate.
shutdownSync() → void
  Shut down target isolate.
toString() → String
  A string representation of this object.
  inherited

## Operators

operator ==(Object other) → bool
  The equality operator.
  inherited

## Static Properties

current → Isolate
  An Isolate 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

create({String? debugName}) → Isolate
  Create a new isolate in the current isolate group.
exit([SendPort? finalMessagePort, Object? message]) → Never
  Terminates the current isolate synchronously.
pinToCurrentThread() → bool
  Pin current isolate to the current OS thread.
resolvePackageUri(Uri packageUri) → Future<Uri?>
  Resolves a `package:` URI to its actual location.
resolvePackageUriSync(Uri packageUri) → Uri?
  Resolves a `package:` URI to its actual location.
run<R>(FutureOr<R> computation(), {String? debugName}) → Future<R>
  Runs `computation` in a new isolate and returns the result.
spawn<T>(void entryPoint(T message), T message, {bool paused = false, bool errorsAreFatal = true, SendPort? onExit, SendPort? onError, String? debugName}) → Future<Isolate>
  Spawns an isolate that shares the same code as the current isolate.
spawnUri(Uri uri, List<String> args, dynamic message, {bool paused = false, SendPort? onExit, SendPort? onError, bool errorsAreFatal = true, bool? checked, Map<String, String>? environment, Uri? packageRoot, Uri? packageConfig, bool automaticPackageResolution = false, String? debugName}) → Future<Isolate>
  Spawns an isolate running the script file specified by `uri`.

## Constants

beforeNextEvent → const int
  Argument to `ping` and `kill`: Ask for action before the next event.
immediate → const int
  Argument to `ping` and `kill`: Ask for immediate action.