diff --git a/codex/slots/proofs/backends/asynccircoms.nim b/codex/slots/proofs/backends/asynccircoms.nim index 8f0bc429..8d1d26ae 100644 --- a/codex/slots/proofs/backends/asynccircoms.nim +++ b/codex/slots/proofs/backends/asynccircoms.nim @@ -56,8 +56,20 @@ proc prove*[H]( let args = ProveTaskArgs(signal: signal, params: self.params) let flowvar = self.tp.spawn proveTask(args, input) - without res =? await awaitThreadResult(signal, flowvar), err: - return failure(err) + without taskRes =? await awaitThreadResult(signal, flowvar), err: + let res: ?!CircomProof = failure(err) + return res + + without proof =? taskRes.mapFailure, err: + let res: ?!CircomProof = failure(err) + return res + + let sigRes = signal.close() + if sigRes.isErr: + return failure(sigRes.error()) + + let pf: CircomProof = proof + success(pf) proc verify*[H]( self: AsyncCircomCompat, proof: CircomProof, inputs: ProofInputs[H] diff --git a/codex/utils/asyncthreads.nim b/codex/utils/asyncthreads.nim index 7dc04882..28fc1f63 100644 --- a/codex/utils/asyncthreads.nim +++ b/codex/utils/asyncthreads.nim @@ -15,11 +15,12 @@ proc awaitThreadResult*[T](signal: ThreadSignalPtr, handle: Flowvar[T]): Future[ var res: T awaitTotal: Duration - while awaitTotal < CompletionTimeout: - if handle.tryComplete(res): - return success(res) - else: - awaitTotal += CompletionRetryDelay - await sleepAsync(CompletionRetryDelay) - return failure("Task signaled finish but didn't return any result within " & $CompletionRetryDelay) \ No newline at end of file + while awaitTotal < CompletionTimeout: + if handle.tryComplete(res): + return success(res) + else: + awaitTotal += CompletionRetryDelay + await sleepAsync(CompletionRetryDelay) + + return failure("Task signaled finish but didn't return any result within " & $CompletionRetryDelay)