enqueue<T> method

Future<T> enqueue<T>(
  1. Future<T> task(), {
  2. Duration autoComplete = const Duration(seconds: 5),
  3. bool catchError = true,
})

Implementation

Future<T> enqueue<T>(
  Future<T> Function() task, {
  Duration autoComplete = const Duration(seconds: 5),
  bool catchError = true,
}) {
  final uuid = Uuid().v4();
  add(uuid, autoComplete: autoComplete);
  return task().catchError((error, stacktrace) {
    if (catchError) {
      return catchErrorWithStackTrace(error, stacktrace);
    } else {
      return error;
    }
  }).whenComplete(
    () => complete(uuid),
  );
}