mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-19 16:24:32 +00:00
[statemachine] state run should not raise error
Crash when run method raises error. This is better than the alternative, which is to silently swallow the error.
This commit is contained in:
parent
50130c33f5
commit
21527bb70f
@ -25,8 +25,11 @@ template makeStateMachine*(MachineType, StateType) =
|
||||
discard
|
||||
|
||||
proc run(machine: MachineType, state: StateType) {.async.} =
|
||||
if next =? await state.run():
|
||||
machine.schedule(Event.transition(state, next))
|
||||
try:
|
||||
if next =? await state.run():
|
||||
machine.schedule(Event.transition(state, next))
|
||||
except CancelledError:
|
||||
discard
|
||||
|
||||
proc scheduler(machine: MachineType) {.async.} =
|
||||
try:
|
||||
@ -37,6 +40,7 @@ template makeStateMachine*(MachineType, StateType) =
|
||||
await machine.running.cancelAndWait()
|
||||
machine.state = next
|
||||
machine.running = machine.run(machine.state)
|
||||
asyncSpawn machine.running
|
||||
except CancelledError:
|
||||
discard
|
||||
|
||||
|
@ -27,6 +27,7 @@ method run(state: State2): Future[?State] {.async.} =
|
||||
await sleepAsync(1.hours)
|
||||
except CancelledError:
|
||||
inc cancellations[1]
|
||||
raise
|
||||
|
||||
method onMoveToNextStateEvent(state: State2): ?State =
|
||||
some State(State3.new())
|
||||
|
Loading…
x
Reference in New Issue
Block a user