try queue setup

This commit is contained in:
Jaremy Creechley 2024-05-20 18:04:05 +03:00
parent 899a0f6f95
commit 9e2820944d
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 6 additions and 8 deletions

View File

@ -30,22 +30,19 @@ proc prove*[H](
): Future[?!CircomProof] {.async.} =
## Generates proof using circom-compat asynchronously
##
without queue =? newSignalQueue[?!CircomProof](), err:
return failure(err)
defer:
if (let res = queue.release(); res.isErr):
error "Error releasing proof queue ", msg = res.error().msg
template spawnTask() =
self.tp.spawn proveTask(self.circom, input, queue)
spawnTask()
without taskRes =? await queue.recvAsync(), err:
let taskRes = await queue.recvAsync()
if (let res = queue.release(); res.isErr):
error "Error releasing proof queue ", msg = res.error().msg
without proofRes =? taskRes, err:
return failure(err)
without proof =? taskRes, err:
without proof =? proofRes, err:
return failure(err)
success(proof)

View File

@ -36,6 +36,7 @@ proc release*[T](queue: SignalQueuePtr[T]): ?!void =
## Call to properly dispose of a SignalQueue.
queue[].chan.close()
if err =? queue[].signal.close().mapFailure.errorOption():
queue[].signal = nil
result = failure(err.msg)
deallocShared(queue)