stop method
Stops once; if startup is pending, waits before releasing its resources.
Implementation
Future<void> stop() {
if (_stopRequested) return stopped;
_stopRequested = true;
final cleanup = _startupFinished
? Future<void>.sync(_service.onStop)
: started
.then<void>((_) {}, onError: (Object _, StackTrace _) {})
.then((_) => _service.onStop());
cleanup.then(
(_) => _stopped.complete(),
onError: (Object error, StackTrace stack) {
lastError = error;
_stopped.completeError(error, stack);
},
);
return stopped;
}