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 (stream == null) {
    warning(
        "Trying to resume the stream probe '$runtimeType' which does not provide a Datum stream. "
        'Have you initialized this probe correctly?');
    return false;
  } else {
    Duration? interval = samplingConfiguration?.interval;
    Duration? duration = samplingConfiguration?.duration;
    if (interval != null && duration != null) {
      // create a recurrent timer that resume sampling
      timer = Timer.periodic(interval, (timer) {
        final StreamSubscription<Datum> newSubscription =
            stream!.listen(onData, onError: onError, onDone: onDone);
        // create a timer that pause the sampling after the specified duration.
        Timer(duration, () async {
          await newSubscription.cancel();
        });
      });
    } else {
      warning(
          '$runtimeType - no valid interval and duration found in sampling configuration: $samplingConfiguration. '
          'Is a valid PeriodicSamplingConfiguration provided?');
    }
  }
  return true;
}