enqueue method

Future<void> enqueue({
  1. bool discardOnDispose = true,
  2. Duration? timeout,
  3. required Future<void> operation(),
  4. FutureOr<void> onTimeout()?,
})

Executes operation in sync meaning that if you wrap any code in this function the code will be executed in place if currently there are no other operations running otherwise function will add operation to queue and it will be executed after all previously executed operations are completed

discardOnDispose - flag indicating that this operation will be canceled when instance is disposed - defaults to true timeout - optional timeout for this operation operation - actual future callback that will be executed onTimeout - optional callback if timeout is reached

Implementation

Future<void> enqueue({
  bool discardOnDispose = true,
  Duration? timeout,
  required Future<void> Function() operation,
  FutureOr<void> Function()? onTimeout,
}) async {
  final syncOperation = SyncFuture(
    cancelOnDispose: discardOnDispose,
    timeout: timeout,
    operation: operation,
    onTimeout: onTimeout,
  );

  _runningFutures.add(syncOperation);

  _enqueueNext();
}