KIsolateContinuous<TArg, TResult> class
A persistent isolate that processes tasks sequentially with priority queuing.
Tasks run one at a time inside a single long-lived isolate, avoiding repeated spawn overhead. This is the right tool when initialisation cost is high (e.g. loading an ML model or opening a database connection).
Priority and starvation prevention: Tasks are dispatched high → medium → low. Every agingThreshold non-low dispatches, the oldest queued low-priority task is forcibly promoted so it cannot wait indefinitely.
Backpressure: execute throws immediately when queued tasks reach maxQueueSize, rather than growing memory without bound.
Isolate-to-main thread safety:
The _dispatching flag is set and cleared only inside port-listener
callbacks, which always run on the main isolate's event loop — no concurrent
mutation possible.
See KIsolateAccess for convenient mixin-based access.
Properties
- agingThreshold → int
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isRunning → bool
-
no setter
- maxQueueSize → int
-
final
- pendingCount → int
-
Total tasks waiting across all priority queues.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void - Kills the isolate. All pending tasks fail with KIsolateException.
-
execute(
TArg arg, {KWorkPriority priority = KWorkPriority.medium}) → Future< TResult> -
Enqueues
argfor execution at the givenpriority. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
spawn<
TArg, TResult> (Future< void> initialize(void registerHandler(void (TArg arg, void respond(TResult)))), {RootIsolateToken? rootIsolateToken, int maxQueueSize = kDefaultMaxQueueSize, int agingThreshold = 10}) → Future<KIsolateContinuous< TArg, TResult> > - Spawns and initialises a persistent isolate worker.