tasksFinished method

Future<bool> tasksFinished({
  1. String group = defaultGroup,
  2. bool includeTasksWaitingToRetry = true,
  3. String? ignoreTaskId,
})

Returns true if tasks in this group are finished

Finished means "not active", i.e. no tasks are enqueued or running, and if includeTasksWaitingToRetry is true (the default), no tasks are waiting to be retried. Finished does not mean that all tasks completed successfully.

This method acts on a group of tasks. If omitted, the defaultGroup is used, which is the group used when you enqueue a task.

If an ignoreTask is provided, it will be excluded from the test. This allows you to test for tasksFinished within the status update callback for a task that just finished. In that situation, that task may still be returned by the platform as 'active', but you already know it is not. Calling tasksFinished while passing that just-finished task will ensure a proper test in that situation.

Implementation

Future<bool> tasksFinished(
    {String group = defaultGroup,
    bool includeTasksWaitingToRetry = true,
    String? ignoreTaskId}) async {
  final tasksInProgress = await allTasks(
      group: group, includeTasksWaitingToRetry: includeTasksWaitingToRetry);
  if (ignoreTaskId != null) {
    tasksInProgress.removeWhere((task) => task.taskId == ignoreTaskId);
  }
  return tasksInProgress.isEmpty;
}