[utils] Add AsyncState to state machine
This commit is contained in:
parent
b52d291785
commit
7841a9692c
|
@ -1,4 +1,5 @@
|
||||||
import pkg/questionable
|
import pkg/questionable
|
||||||
|
import pkg/chronos
|
||||||
import ./optionalcast
|
import ./optionalcast
|
||||||
|
|
||||||
## Implementation of the the state pattern:
|
## Implementation of the the state pattern:
|
||||||
|
@ -84,3 +85,18 @@ proc switch*(machine: StateMachine, newState: State) =
|
||||||
proc switch*(oldState, newState: State) =
|
proc switch*(oldState, newState: State) =
|
||||||
if context =? oldState.context:
|
if context =? oldState.context:
|
||||||
context.switch(newState)
|
context.switch(newState)
|
||||||
|
|
||||||
|
type
|
||||||
|
AsyncState* = ref object of State
|
||||||
|
|
||||||
|
method enterAsync(state: AsyncState) {.base, async.} =
|
||||||
|
discard
|
||||||
|
|
||||||
|
method exitAsync(state: AsyncState) {.base, async.} =
|
||||||
|
discard
|
||||||
|
|
||||||
|
method enter(state: AsyncState) =
|
||||||
|
asyncSpawn state.enterAsync()
|
||||||
|
|
||||||
|
method exit(state: AsyncState) =
|
||||||
|
asyncSpawn state.exitAsync()
|
||||||
|
|
Loading…
Reference in New Issue