AsyncLock class

A lightweight sequential async lock that serializes tasks through a future chain, preventing concurrent access to shared mutable state that is not thread-safe (e.g. a CompiledModel slot or interpreter input/output buffers).

Tasks registered via run execute strictly first-in-first-out: each task waits for every previously-registered task to settle before it starts, so no two tasks ever overlap. A task that throws propagates its error to its own caller but does not poison the chain: tasks registered after it still run.

Registration is synchronous, so calling run twice in a row (without awaiting) reserves slots in call order.

final lock = AsyncLock();
final a = lock.run(() => inferA()); // runs first
final b = lock.run(() => inferB()); // runs after a settles

Constructors

AsyncLock()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run<T>(Future<T> task()) Future<T>
Runs task after all previously-registered tasks have settled, and returns its result (or rethrows its error) to the caller.
toString() String
A string representation of this object.
inherited

Operators

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