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.started = true
|
||||
try:
|
||||
discard machine.scheduler().track(machine)
|
||||
machine.schedule(Event.transition(machine.state, initialState))
|
||||
except CancelledError as e:
|
||||
discard
|
||||
except CatchableError as e:
|
||||
error("Error in scheduler", error = e.msg)
|
||||
machine.scheduler()
|
||||
.track(machine)
|
||||
.cancelled(proc() = trace("machine.scheduler cancelled, swallowing"))
|
||||
.catch((err: ref CatchableError) =>
|
||||
error("Error in scheduler", error = err.msg)
|
||||
)
|
||||
machine.schedule(Event.transition(machine.state, initialState))
|
||||
|
||||
proc stop*(machine: Machine) {.async.} =
|
||||
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.} =
|
||||
inc runs[1]
|
||||
echo "State2 run, runs: ", $runs
|
||||
try:
|
||||
await sleepAsync(1.hours)
|
||||
except CancelledError:
|
||||
|
@ -37,7 +36,6 @@ method run(state: State3, machine: Machine): Future[?State] {.async.} =
|
|||
|
||||
method run(state: State4, machine: Machine): Future[?State] {.async.} =
|
||||
inc runs[3]
|
||||
echo "State4 run, runs: ", $runs
|
||||
raise newException(ValueError, "failed")
|
||||
|
||||
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 =
|
||||
inc errors[3]
|
||||
echo "State4 onError, errors: ", $errors
|
||||
some State(State2.new())
|
||||
|
||||
asyncchecksuite "async state machines":
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import pkg/chronos
|
||||
import pkg/ethers
|
||||
import pkg/ethers/erc20
|
||||
from pkg/libp2p import Cid
|
||||
import pkg/codex/contracts/marketplace as mp
|
||||
import pkg/codex/periods
|
||||
|
|
Loading…
Reference in New Issue