From 8806166a26a133708dd26ba43ca8ad80cc363af9 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:53:33 +1100 Subject: [PATCH] cleanup --- codex/utils/asyncstatemachine.nim | 14 +++++++------- tests/codex/utils/testasyncstatemachine.nim | 3 --- tests/integration/marketplacesuite.nim | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/codex/utils/asyncstatemachine.nim b/codex/utils/asyncstatemachine.nim index 3f15af31..2d02110d 100644 --- a/codex/utils/asyncstatemachine.nim +++ b/codex/utils/asyncstatemachine.nim @@ -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: diff --git a/tests/codex/utils/testasyncstatemachine.nim b/tests/codex/utils/testasyncstatemachine.nim index f65bb7ea..a114f7c9 100644 --- a/tests/codex/utils/testasyncstatemachine.nim +++ b/tests/codex/utils/testasyncstatemachine.nim @@ -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": diff --git a/tests/integration/marketplacesuite.nim b/tests/integration/marketplacesuite.nim index 01bfd712..d3b1ef57 100644 --- a/tests/integration/marketplacesuite.nim +++ b/tests/integration/marketplacesuite.nim @@ -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