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 (await requestPermissions()) {
    if (stream == null) {
      warning(
        "Trying to start the stream probe '$runtimeType' which does not provide a measurement 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 starts sampling
        _timer = Timer.periodic(interval, (timer) {
          _subscription = stream?.listen(
            _onData,
            onError: _onError,
            onDone: _onDone,
          );
          // create a timer that stops the sampling after the specified duration.
          Timer(duration, () async => await _subscription?.cancel());
        });
      } else {
        warning(
          '$runtimeType - no valid interval and duration found in sampling configuration: $samplingConfiguration. '
          'Is a valid PeriodicSamplingConfiguration provided?',
        );
      }
    }
    return true;
  } else {
    return false;
  }
}