acquire method
Acquires the assertion for level. No-op for off and when already
acquired; a spawn failure warns (via the injected
PowerAssertionController onWarn) and leaves the session
unguarded.
Implementation
Future<void> acquire() {
if (_handle != null || _acquiring != null) return Future<void>.value();
final options = powerAssertionOptions(level);
if (options == null) return Future<void>.value();
final done = Completer<void>();
_acquiring = done.future;
() async {
try {
_handle = await runner.acquire(options);
} on Object catch (error) {
_warn('sleep prevention unavailable: $error');
} finally {
_acquiring = null;
done.complete();
}
}();
return done.future;
}