add<T> method

Future<T> add<T>(
  1. Future<T> f(), {
  2. Duration? buffer,
})

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;
}