in MobiusCore/Source/AsyncStartStopStateMachine.swift [108:125]
func transitionToStopped(by transition: (RunningState) throws -> StoppedState) throws {
dispatchPrecondition(condition: .notOnQueue(queue))
try queue.sync {
switch snapshot() {
case .stopped:
throw Error.wrongState
case .running(let runningState):
rawState.value = .transitioningToStopped
do {
let stoppedState = try transition(runningState)
become(stopped: stoppedState)
} catch {
rawState.value = .running
throw error
}
}
}
}