onResume method

  1. @override
Future<bool> onResume()
override

Callback when this executor is resumed. Returns true if successfully resumed, false otherwise.

Implementation

@override
Future<bool> onResume() async {
  // enqueue immediately if not already on the list, then keep checking once
  // pr minute - otherwise the first check (and task) is delayed a full minute.
  // A notified, started or canceled task is still on the list - only a done
  // or expired one is not.
  void enqueueIfMissing() {
    if (!AppTaskController().userTaskQueue.any((task) =>
        task.name == configuration!.taskName &&
        task.state != UserTaskState.done &&
        task.state != UserTaskState.expired)) {
      onTrigger();
    }
  }

  enqueueIfMissing();
  // Use the inherited [timer], which the base onPause()/onDispose() cancel.
  timer = Timer.periodic(Duration(minutes: 1), (_) => enqueueIfMissing());

  return true;
}