onResume method
Callback when this executor is resumed. Returns true if successfully resumed, false otherwise.
Implementation
@override
Future<bool> onResume() async {
// Early out if no probes.
if (probes.isEmpty) return true;
// Early out if already running (this is a background task)
if (state == ExecutorState.Resumed) {
warning(
'$runtimeType - Trying to resume $this but it is already resumed. Ignoring this.',
);
return false;
}
// Listen to pause this background executor when all of its underlying
// probes have paused - Issue #384
_subscription = states
.where((event) => event == ExecutorState.Paused)
.listen((_) {
if (haveAllProbesPaused && state == ExecutorState.Resumed) {
debug(
'$runtimeType - All probes are paused - pausing this $this too.',
);
pause();
}
});
// Check if the devices for this task is connected.
await connectAllConnectableDevices();
if (configuration?.duration != null) {
// If the task has a duration (optional), stop it again after this duration has passed.
Timer(
Duration(seconds: configuration!.duration!.inSeconds.truncate()),
() => pause(),
);
}
// Now - finally - we can start the probes.
return await super.onResume();
}