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 {
  Duration? interval = samplingConfiguration?.interval;
  Duration? duration = samplingConfiguration?.duration;
  if (interval != null && duration != null) {
    // create a recurrent timer that every [frequency] resumes the buffering.
    timer = Timer.periodic(interval, (Timer t) {
      onSamplingStart();
      // create a timer that stops the buffering after the specified [duration].
      Timer(duration, () async {
        onSamplingEnd();
        // collect the datum
        try {
          Datum? datum = await getDatum();
          if (datum != null) addData(datum);
        } catch (error) {
          addError(error);
        }
      });
    });
  } else {
    warning(
        '$runtimeType - no valid interval and duration found in sampling configuration: $samplingConfiguration. '
        'Is a valid PeriodicSamplingConfiguration provided?');
    return false;
  }
  return true;
}