add<T> method
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);
});
}
}