TaskSequencer<T extends Object> class

Manages a chain of dependent tasks, ensuring they execute sequentially.

A TaskSequencer processes tasks one after another, passing the result of the completed task to the next one in the chain. It supports both sync and async tasks and includes a re-entrant queue to handle new tasks that are added while an existing sequence is already running.

Isolate sendability

A TaskSequencer is sendable through SendPort iff:

  1. Every handler ever passed to then / TaskSequencer.new (including onPrevError) is a top-level function or static method — enforced by the @sendable lint.
  2. The current _current result is a Sync (synchronous) outcome — the moment any handler returns an Async, _current becomes isolate-local until that future settles. A freshly-constructed sequencer satisfies this trivially.

Constructors

TaskSequencer({@noFutures @sendable TOnTaskError? onPrevError, bool eagerError = false, Duration? minTaskDuration})

Properties

completion TResolvableOption<T>
A Resolvable that represents the final result of the entire sequence.
no setter
hashCode int
The hash code for this object.
no setterinherited
isExecuting bool
no setter
isNotExecuting bool
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

newBatch() SequencedTaskBatch<T>
Creates a new SequencedTaskBatch that is bound to this sequencer.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
then(TTaskHandler<T> handler, {TOnTaskError? onPrevError, bool? eagerError, Duration? minTaskDuration}) TResolvableOption<T>
Appends a new task to the sequence.
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

convertHandler<T extends Object>(FutureOr<T?> handler(T? prev, Err<Object>? err)) TTaskHandler<T>