[statemachine] use lambda syntax

This commit is contained in:
Mark Spanbroek 2023-02-09 13:38:39 +01:00
parent 8565f1bb85
commit 87c16512eb
No known key found for this signature in database
GPG Key ID: FBE3E9548D427C00
1 changed files with 3 additions and 12 deletions

View File

@ -1,3 +1,4 @@
import std/sugar
import pkg/asynctest
import pkg/questionable
import pkg/chronos
@ -54,20 +55,10 @@ suite "async state machines":
test "state2 moves to state3 on event":
machine.start(state2)
proc moveToNextStateEvent(state: State): ?State =
state.onMoveToNextStateEvent()
machine.schedule(moveToNextStateEvent)
machine.schedule(state => state.onMoveToNextStateEvent())
check eventually runs == [0, 1, 1]
test "state transition will cancel the running state":
machine.start(state2)
proc moveToNextStateEvent(state: State): ?State =
state.onMoveToNextStateEvent()
machine.schedule(moveToNextStateEvent)
machine.schedule(state => state.onMoveToNextStateEvent())
check eventually cancellations == [0, 1, 0]