try queue setup

This commit is contained in:
Jaremy Creechley 2024-05-20 18:32:14 +03:00
parent f90c4cdb66
commit 2beb5ab2aa
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 5 additions and 6 deletions

View File

@ -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() =

View File

@ -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