onStart method

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

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

Implementation

@override
Future<bool> onStart() async {
  if (await requestPermissions()) {
    Duration? interval = samplingConfiguration?.interval;
    if (interval != null) {
      _bufferingStreamSubscription = bufferingStream.listen(
        onSamplingData,
        onError: _onError,
        onDone: _onDone,
      );
      _timer = Timer.periodic(interval, (_) async {
        try {
          Measurement? measurement = await getMeasurement();
          if (measurement != null) addMeasurement(measurement);
        } catch (error) {
          addError(error);
        }
      });
    } else {
      warning(
          '$runtimeType - no valid interval found in sampling configuration: $samplingConfiguration. '
          'Is a valid IntervalSamplingConfiguration provided?');
      return false;
    }
    return true;
  } else {
    return false;
  }
}