mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-07 16:03:13 +00:00
[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…
x
Reference in New Issue
Block a user