From 2beb5ab2aa5350ac857cf71a8c2461bd3a58006b Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Mon, 20 May 2024 18:32:14 +0300 Subject: [PATCH] try queue setup --- codex/slots/proofs/backends/asynccircoms.nim | 2 +- codex/utils/asyncthreads.nim | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/codex/slots/proofs/backends/asynccircoms.nim b/codex/slots/proofs/backends/asynccircoms.nim index 2a632873..b7b6fc51 100644 --- a/codex/slots/proofs/backends/asynccircoms.nim +++ b/codex/slots/proofs/backends/asynccircoms.nim @@ -28,7 +28,7 @@ proc prove*[H]( ): Future[?!CircomProof] {.async.} = ## Generates proof using circom-compat asynchronously ## - without queue =? newSignalQueue[?!CircomProof](), err: + without queue =? newSignalQueue[?!CircomProof](maxItems=1), err: return failure(err) template spawnTask() = diff --git a/codex/utils/asyncthreads.nim b/codex/utils/asyncthreads.nim index b4bf9cde..e9cd08b7 100644 --- a/codex/utils/asyncthreads.nim +++ b/codex/utils/asyncthreads.nim @@ -54,9 +54,7 @@ proc newSignalQueue*[T](maxItems: int = 0): ?!SignalQueuePtr[T] = result[].chan.open(maxItems) proc send*[T](queue: SignalQueuePtr[T], msg: T): ?!void {.raises: [].} = - ## Sends a message from a regular thread. `msg` is deep copied. - ## Note: may be blocking. - ## + ## Sends a message from a regular thread. `msg` is deep copied. May block try: queue[].chan.send(msg) except Exception as exc: @@ -64,9 +62,10 @@ proc send*[T](queue: SignalQueuePtr[T], msg: T): ?!void {.raises: [].} = without wasSent =? queue[].signal.fireSync(InfiniteDuration).mapFailure, err: return failure(err) - if not wasSent: + if wasSent: + return ok() + else: return failure("ThreadSignalPtr not signalled in time") - result = ok() proc recvAsync*[T](queue: SignalQueuePtr[T]): Future[?!T] {.async.} = ## Async compatible receive from queue. Pauses async execution until