add<T> method
Adds a new function to the queue and returns a completer for the result.
If the buffer parameter is provided, the function is wrapped in a new
function that waits for the buffer duration before executing the
original function.
Implementation
Future<T> add<T>(
Future<T> Function() f, {
Duration? buffer,
}) async {
final q = _Queueable<T>(
buffer == null
? f
: () async => (await Future.wait([
f(),
Future.delayed(buffer),
]))
.first,
);
this._queue.add(q);
await this._execute();
return q._completer.future;
}