cleanup
This commit is contained in:
parent
4260cdd514
commit
8806166a26
|
@ -90,13 +90,13 @@ proc start*(machine: Machine, initialState: State) =
|
||||||
machine.scheduled = newAsyncQueue[Event]()
|
machine.scheduled = newAsyncQueue[Event]()
|
||||||
|
|
||||||
machine.started = true
|
machine.started = true
|
||||||
try:
|
machine.scheduler()
|
||||||
discard machine.scheduler().track(machine)
|
.track(machine)
|
||||||
machine.schedule(Event.transition(machine.state, initialState))
|
.cancelled(proc() = trace("machine.scheduler cancelled, swallowing"))
|
||||||
except CancelledError as e:
|
.catch((err: ref CatchableError) =>
|
||||||
discard
|
error("Error in scheduler", error = err.msg)
|
||||||
except CatchableError as e:
|
)
|
||||||
error("Error in scheduler", error = e.msg)
|
machine.schedule(Event.transition(machine.state, initialState))
|
||||||
|
|
||||||
proc stop*(machine: Machine) {.async.} =
|
proc stop*(machine: Machine) {.async.} =
|
||||||
if not machine.started:
|
if not machine.started:
|
||||||
|
|
|
@ -25,7 +25,6 @@ method run(state: State1, machine: Machine): Future[?State] {.async.} =
|
||||||
|
|
||||||
method run(state: State2, machine: Machine): Future[?State] {.async.} =
|
method run(state: State2, machine: Machine): Future[?State] {.async.} =
|
||||||
inc runs[1]
|
inc runs[1]
|
||||||
echo "State2 run, runs: ", $runs
|
|
||||||
try:
|
try:
|
||||||
await sleepAsync(1.hours)
|
await sleepAsync(1.hours)
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
|
@ -37,7 +36,6 @@ method run(state: State3, machine: Machine): Future[?State] {.async.} =
|
||||||
|
|
||||||
method run(state: State4, machine: Machine): Future[?State] {.async.} =
|
method run(state: State4, machine: Machine): Future[?State] {.async.} =
|
||||||
inc runs[3]
|
inc runs[3]
|
||||||
echo "State4 run, runs: ", $runs
|
|
||||||
raise newException(ValueError, "failed")
|
raise newException(ValueError, "failed")
|
||||||
|
|
||||||
method onMoveToNextStateEvent*(state: State): ?State {.base, upraises:[].} =
|
method onMoveToNextStateEvent*(state: State): ?State {.base, upraises:[].} =
|
||||||
|
@ -60,7 +58,6 @@ method onError(state: State3, error: ref CatchableError): ?State =
|
||||||
|
|
||||||
method onError(state: State4, error: ref CatchableError): ?State =
|
method onError(state: State4, error: ref CatchableError): ?State =
|
||||||
inc errors[3]
|
inc errors[3]
|
||||||
echo "State4 onError, errors: ", $errors
|
|
||||||
some State(State2.new())
|
some State(State2.new())
|
||||||
|
|
||||||
asyncchecksuite "async state machines":
|
asyncchecksuite "async state machines":
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/ethers
|
import pkg/ethers/erc20
|
||||||
from pkg/libp2p import Cid
|
from pkg/libp2p import Cid
|
||||||
import pkg/codex/contracts/marketplace as mp
|
import pkg/codex/contracts/marketplace as mp
|
||||||
import pkg/codex/periods
|
import pkg/codex/periods
|
||||||
|
|
Loading…
Reference in New Issue