AsyncCallQueue class

AsyncCallQueue provides a queuing mechanism to prevent concurrent access to asynchronous code via the queueCall method, and provides a way to delay execute code via the delayCall method.

It also provides a way to know if subsequent calls are waiting to execute, which allows the currently executing call to, for example, cancel doing some work and return sooner.

The dispose method should be called when the AsyncCallQueue object is no longer needed.

Constructors

AsyncCallQueue({bool debugMode = false})

Properties

debugMode bool
final
hashCode int
The hash code for this object.
no setterinherited
latestCallId int
Every call is given a unique ID; this returns the most recent call's ID.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

delayCall(FutureOr func(AsyncCallQueue queue, int callId), {Duration delay = const Duration(seconds: 1), bool preventConcurrentAccess = true}) → void
Calls the func after the delay. If another call comes in before the delay finishes, the call is cancelled and the delay is restarted.
dispose() → void
Call the dispose function when this object is no longer needed. It will cancel any pending delayed call. The dispose function must only be called once.
hasCallsWaitingAfter(int callId) bool
Returns true if one or more calls have been made after the call with the given callId. Useful, for example, if you want to cancel doing some work in an async function if subsequent calls are waiting to execute.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
queueCall<T>(FutureOr<T> func(AsyncCallQueue queue, int callId), {Duration? timeout}) Future<T>
Calls the func immediately, unless a previous call to an async func is still executing (i.e. awaiting an async result), in which case it waits for the previous call to finish before calling the given func.
toString() String
A string representation of this object.
inherited

Operators

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