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 {
  if (configuration!.schedule.isAfter(DateTime.now())) {
    warning('The schedule of the DateTimeTrigger cannot be in the past.');
    return false;
  } else {
    var delay = configuration!.schedule.difference(DateTime.now());
    var duration = configuration?.duration;
    timer = Timer(delay, () {
      // after the waiting time (delay) is over, resume this trigger
      super.onResume();
      if (duration != null) {
        // create a timer that stop the sampling after the specified duration.
        // if the duration is null, the sampling never stops, i.e. runs forever.
        Timer(duration, () {
          stop();
        });
      }
    });
  }
  return true;
}