avoid `Taskpool.spawn` within `{.async.}` for Nim 2.0 (#5393)
In Nim 2.0, attempting to use `Taskpool.spawn` inside `{.async.}` `proc` leads to `Error: cannot generate destructor for generic type: Isolated`. Add an intermediate wrapper `proc` that performs the `spawn` operation to workaround the problem.
This commit is contained in:
parent
dbb1a63ca9
commit
8ffb80e954
|
@ -228,6 +228,13 @@ proc batchVerifyTask(task: ptr BatchTask) {.nimcall.} =
|
|||
|
||||
discard task[].signal.fireSync()
|
||||
|
||||
proc spawnBatchVerifyTask(tp: Taskpool, task: ptr BatchTask) =
|
||||
# Inlining this `proc` leads to compilation problems on Nim 2.0
|
||||
# - Error: cannot generate destructor for generic type: Isolated
|
||||
# Workaround: Ensure that `tp.spawn` is not used within an `{.async.}` proc
|
||||
# Possibly related to: https://github.com/nim-lang/Nim/issues/22305
|
||||
tp.spawn batchVerifyTask(task)
|
||||
|
||||
proc batchVerifyAsync*(
|
||||
verifier: ref BatchVerifier, signal: ThreadSignalPtr,
|
||||
batch: ref Batch): Future[bool] {.async.} =
|
||||
|
@ -245,7 +252,7 @@ proc batchVerifyAsync*(
|
|||
let taskPtr = addr task
|
||||
doAssert verifier[].taskpool.numThreads > 1,
|
||||
"Must have at least one separate thread or signal will never be fired"
|
||||
verifier[].taskpool.spawn batchVerifyTask(taskPtr)
|
||||
verifier[].taskpool.spawnBatchVerifyTask(taskPtr)
|
||||
await signal.wait()
|
||||
task.ok.load()
|
||||
|
||||
|
|
Loading…
Reference in New Issue