executeTasks method

  1. @override
TResolvableOption<T> executeTasks()
override

Executes all tasks in the queue concurrently using a custom wait utility.

The tasks are started in parallel, and this method returns a Resolvable that will complete once all tasks have finished.

Implementation

@override
TResolvableOption<T> executeTasks() {
  _executionCount = tasks.length;
  _executionIndex = 0;
  final itemFactories = tasks.map(
    (task) =>
        () => task
            .handler(Ok(None<T>()))
            .withMinDuration(_minTaskDuration ?? task.minTaskDuration)
            .then((e) {
              _executionIndex++;
              return _onTaskCompleted?.call(task, executionProgress) ??
                  syncUnit();
            })
            .flatten()
            .value,
  );
  _internalIsExecuting = true;
  return Resolvable(
    () => waitF<Option<T>>(
      itemFactories,
      (_) => const None(),
      eagerError: _eagerError,
      onError: (error, stackTrace) {
        return _onError?.call(Err(error, stackTrace: stackTrace)).value;
      },
    ),
  ).whenComplete((e) {
    _internalIsExecuting = false;
    return e;
  });
}