mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-27 01:40:44 +00:00
work around windows - renames
This commit is contained in:
parent
d96ca3f146
commit
b2f7e417f3
@ -30,10 +30,9 @@ proc prove*[H](
|
|||||||
self: AsyncCircomCompat, input: ProofInputs[H]
|
self: AsyncCircomCompat, input: ProofInputs[H]
|
||||||
): Future[?!CircomProof] {.async.} =
|
): Future[?!CircomProof] {.async.} =
|
||||||
## Generates proof using circom-compat asynchronously
|
## Generates proof using circom-compat asynchronously
|
||||||
let queueRes = newSignalQueue[?!CircomProof](maxItems = 1)
|
##
|
||||||
if queueRes.isErr:
|
without queue =? newSignalQueue[?!CircomProof](maxItems = 1), qerr:
|
||||||
return failure queueRes.error()
|
return failure(qerr)
|
||||||
let queue = queueRes.get()
|
|
||||||
|
|
||||||
proc spawnTask() =
|
proc spawnTask() =
|
||||||
self.tp.spawn proveTask(self.circom, input, queue)
|
self.tp.spawn proveTask(self.circom, input, queue)
|
||||||
@ -43,10 +42,10 @@ proc prove*[H](
|
|||||||
let taskRes = await queue.recvAsync()
|
let taskRes = await queue.recvAsync()
|
||||||
if (let res = queue.release(); res.isErr):
|
if (let res = queue.release(); res.isErr):
|
||||||
error "Error releasing proof queue ", msg = res.error().msg
|
error "Error releasing proof queue ", msg = res.error().msg
|
||||||
without proofRes =? taskRes, exc:
|
without proofRes =? taskRes, perr:
|
||||||
return failure(exc)
|
return failure(perr)
|
||||||
without proof =? proofRes, exc:
|
without proof =? proofRes, perr:
|
||||||
return failure(exc)
|
return failure(perr)
|
||||||
|
|
||||||
success(proof)
|
success(proof)
|
||||||
|
|
||||||
@ -66,8 +65,8 @@ proc verify*[H](
|
|||||||
): Future[?!bool] {.async.} =
|
): Future[?!bool] {.async.} =
|
||||||
## Verify a proof using a ctx
|
## Verify a proof using a ctx
|
||||||
##
|
##
|
||||||
without queue =? newSignalQueue[?!bool](maxItems = 1), exc:
|
without queue =? newSignalQueue[?!bool](maxItems = 1), qerr:
|
||||||
return failure(exc)
|
return failure(qerr)
|
||||||
|
|
||||||
proc spawnTask() =
|
proc spawnTask() =
|
||||||
self.tp.spawn verifyTask(self.circom, proof, inputs, queue)
|
self.tp.spawn verifyTask(self.circom, proof, inputs, queue)
|
||||||
@ -77,16 +76,14 @@ proc verify*[H](
|
|||||||
let taskRes = await queue.recvAsync()
|
let taskRes = await queue.recvAsync()
|
||||||
if (let res = queue.release(); res.isErr):
|
if (let res = queue.release(); res.isErr):
|
||||||
error "Error releasing proof queue ", msg = res.error().msg
|
error "Error releasing proof queue ", msg = res.error().msg
|
||||||
without verifyRes =? taskRes, exc:
|
without verifyRes =? taskRes, verr:
|
||||||
return failure(exc)
|
return failure(verr)
|
||||||
without verified =? verifyRes, exc:
|
without verified =? verifyRes, verr:
|
||||||
return failure(exc)
|
return failure(verr)
|
||||||
|
|
||||||
success(verified)
|
success(verified)
|
||||||
|
|
||||||
proc init*(
|
proc init*(_: type AsyncCircomCompat, params: CircomCompatParams, tp: Taskpool): AsyncCircomCompat =
|
||||||
_: type AsyncCircomCompat, params: CircomCompatParams, tp: Taskpool
|
|
||||||
): AsyncCircomCompat =
|
|
||||||
## Create a new async circom
|
## Create a new async circom
|
||||||
##
|
##
|
||||||
let circom = CircomCompat.init(params)
|
let circom = CircomCompat.init(params)
|
||||||
|
@ -28,18 +28,13 @@ proc release*[T](queue: SignalQueuePtr[T]): ?!void =
|
|||||||
deallocShared(queue)
|
deallocShared(queue)
|
||||||
return success()
|
return success()
|
||||||
|
|
||||||
proc newSignalQueue*[T](
|
proc newSignalQueue*[T](maxItems: int = 0): ?!SignalQueuePtr[T] =
|
||||||
maxItems: int = 0
|
|
||||||
): Result[SignalQueuePtr[T], ref CatchableError] =
|
|
||||||
## Create a signal queue compatible with Chronos async.
|
## Create a signal queue compatible with Chronos async.
|
||||||
let queue = cast[ptr SignalQueue[T]](allocShared0(sizeof(SignalQueue[T])))
|
result = success cast[ptr SignalQueue[T]](allocShared0(sizeof(SignalQueue[T])))
|
||||||
let sigRes = ThreadSignalPtr.new()
|
without signal =? ThreadSignalPtr.new().mapFailure, sigErr:
|
||||||
if sigRes.isErr():
|
return failure(sigErr)
|
||||||
return failure((ref CatchableError)(msg: sigRes.error()))
|
result[].signal = signal
|
||||||
else:
|
result[].chan.open(maxItems)
|
||||||
queue[].signal = sigRes.get()
|
|
||||||
queue[].chan.open(maxItems)
|
|
||||||
return success(queue)
|
|
||||||
|
|
||||||
proc send*[T](queue: SignalQueuePtr[T], msg: T): ?!void {.raises: [].} =
|
proc send*[T](queue: SignalQueuePtr[T], msg: T): ?!void {.raises: [].} =
|
||||||
## Sends a message from a regular thread. `msg` is deep copied. May block
|
## Sends a message from a regular thread. `msg` is deep copied. May block
|
||||||
@ -48,10 +43,9 @@ proc send*[T](queue: SignalQueuePtr[T], msg: T): ?!void {.raises: [].} =
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
return failure(exc.msg)
|
return failure(exc.msg)
|
||||||
|
|
||||||
let res = queue[].signal.fireSync(InfiniteDuration).mapFailure()
|
without wasSent =? queue[].signal.fireSync(InfiniteDuration).mapFailure, sigErr:
|
||||||
if res.isErr:
|
return failure(sigErr)
|
||||||
return failure(res.error())
|
if wasSent:
|
||||||
if res.get():
|
|
||||||
return ok()
|
return ok()
|
||||||
else:
|
else:
|
||||||
return failure("ThreadSignalPtr not signalled in time")
|
return failure("ThreadSignalPtr not signalled in time")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user