diff --git a/codex/slots/proofs/backends/asynccircoms.nim b/codex/slots/proofs/backends/asynccircoms.nim index 8d1d26ae..205a7348 100644 --- a/codex/slots/proofs/backends/asynccircoms.nim +++ b/codex/slots/proofs/backends/asynccircoms.nim @@ -64,10 +64,6 @@ proc prove*[H]( let res: ?!CircomProof = failure(err) return res - let sigRes = signal.close() - if sigRes.isErr: - return failure(sigRes.error()) - let pf: CircomProof = proof success(pf) diff --git a/codex/utils/asyncthreads.nim b/codex/utils/asyncthreads.nim index 28fc1f63..68f9bad5 100644 --- a/codex/utils/asyncthreads.nim +++ b/codex/utils/asyncthreads.nim @@ -12,15 +12,22 @@ const proc awaitThreadResult*[T](signal: ThreadSignalPtr, handle: Flowvar[T]): Future[?!T] {.async.} = await wait(signal) + proc closeSig() = + let sigRes = signal.close() + if sigRes.isErr: + return failure(sigRes.error()) + var res: T awaitTotal: Duration while awaitTotal < CompletionTimeout: - if handle.tryComplete(res): + if handle.tryComplete(res): ## TODO: pretty sure this leaks currently + closeSig() return success(res) else: awaitTotal += CompletionRetryDelay await sleepAsync(CompletionRetryDelay) + closeSig() return failure("Task signaled finish but didn't return any result within " & $CompletionRetryDelay)