APIIsolatePool class

A pool of long-lived worker Isolates, running computations like Isolate.run, with at most maxIsolates isolates at the same time.

  • The workers are spawned on demand and reused: the state initialized by a computation (e.g., the tables of an encoder) is kept between runs.
  • A computation is queued (FIFO) while all the maxIsolates workers are busy, instead of spawning a new isolate.
  • A worker idle for idleTimeout exits (and is disposed): spawned again on demand.
  • An idle worker doesn't keep the current isolate (or the program) alive.
  • A computation that throws completes with a RemoteError. If a worker exits (e.g., an unrecoverable error), its computation fails and the worker is replaced on demand.

Constructors

APIIsolatePool({int? maxIsolates, Duration? idleTimeout = defaultIdleTimeout, String debugName = 'APIIsolatePool'})

Properties

debugName → String
The debug name of the worker isolates.
final
hashCode → int
The hash code for this object.
no setterinherited
idleTimeout → Duration?
The time a worker can stay idle before it exits and is disposed. If null, the workers don't exit when idle.
final
isClosed → bool
Returns true if close was called.
no setter
isolatesLength → int
The number of worker isolates (spawned, spawning or exiting).
no setter
maxIsolates → int
The maximum number of worker isolates (and concurrent computations).
final
queuedLength → int
The number of computations waiting for a worker.
no setter
runningLength → int
The number of computations running.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → void
Closes this pool: the queued computations fail with a StateError, the running ones complete, then the workers exit.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run<R>(FutureOr<R> computation()) → Future<R>
Runs computation in a worker isolate and returns its result. Same rules as Isolate.run for computation (it must be sendable) and its result.
toString() → String
A string representation of this object.
override

Operators

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

Static Properties

defaultMaxIsolates → int
The default maxIsolates: see defaultMaxIsolatesFor (one worker).
no setter

Static Methods

defaultMaxIsolatesFor({int workers = 1}) → int
The default maxIsolates for each of workers isolates with their own pool (e.g., the APIServerWorkers): half of the processors divided by workers, from 2 to 4.

Constants

defaultIdleTimeout → const Duration
The default idleTimeout.