add<T> method

FutureOr<T> add<T>(
  1. FutureOr<T> function(
    1. dynamic previous
    ), {
  2. Duration? buffer,
})

Adds a function to the queue that processes the previous value. Applies an optional buffer duration to throttle the execution.

Implementation

FutureOr<T> add<T>(
  FutureOr<T> Function(dynamic previous) function, {
  Duration? buffer,
}) {
  final buffer1 = buffer ?? _buffer;
  if (buffer1 == null) {
    return _enqueue<T>(function);
  } else {
    return _enqueue<T>((previous) {
      return Future.wait<dynamic>([
        Future.value(function(previous)),
        Future<void>.delayed(buffer1),
      ]).then((e) => e.first as T);
    });
  }
}