Waiter<T> class

Manages a collection of operations for deferred, batched execution.

Unlike Future.wait, which requires a list of already-running Future instances, a Waiter collects functions (operations) that have not yet been executed.

This allows you to build up a queue of tasks from different parts of your application and then run them all at once by calling wait.

{@tool snippet}

final waiter = Waiter<String>();

// Define tasks without running them.
waiter.add(() => 'Sync task complete');
waiter.add(() async {
  await Future.delayed(Duration(milliseconds: 20));
  return 'Async task complete';
});

// Execute the entire batch.
final results = await waiter.wait();
print(results); // (Sync task complete, Async task complete)

{@end-tool}

Constructors

Waiter.new({_TOnErrorCallback? onError, List<_TOperation<T>> operations = const []})
Creates a waiter to queue and manage deferred operations.

Properties

hashCode int
The hash code for this object.
no setterinherited
operations List<_TOperation<T>>
A read-only view of the pending operations.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(_TOperation<T> operation) → void
Adds a deferred operation to the queue.
addAll(Iterable<_TOperation<T>> operations) → void
Adds multiple deferred operations to the queue.
clear() → void
Removes all pending operations from the queue.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(_TOperation<T> operation) → void
Removes a specific operation from the queue.
toString() String
A string representation of this object.
inherited
wait({_TOnErrorCallback? onError, bool eagerError = true}) FutureOr<Iterable<T>>
Executes all queued operations and returns their results.

Operators

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