This commit is contained in:
Jaremy Creechley 2024-02-09 22:22:36 -07:00
parent 51459a8c9b
commit 3a6ef39530
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 4 additions and 4 deletions

View File

@ -12,6 +12,6 @@ type
proc newJobQueue*[T](maxItems: int = 0, taskpool: Taskpool = Taskpool.new()): JobQueue[T] {.raises: [ApatheiaSignalErr].} =
JobQueue[T](queue: newSignalQueue[T](maxItems), taskpool: taskpool)
template awaitSpawn*[T](jobs: JobQueue[T], exp: untyped): T =
template awaitJob*[T](jobs: JobQueue[T], exp: typed): auto =
jobs.taskpool.spawn(exp)
await wait(jobs.queue)

View File

@ -11,13 +11,13 @@ import apatheia/jobs
## todo: setup basic async + threadsignal + taskpools example here
##
proc addNums(a, b: float): float =
proc addNumsRaw(a, b: float): float =
os.sleep(500)
echo "adding: ", a, " + ", b
return a + b
proc addNums(queue: SignalQueue[float], a, b: float) =
let res = addNums(a, b)
let res = addNumsRaw(a, b)
discard queue.send(res)
suite "async tests":
@ -29,7 +29,7 @@ suite "async tests":
asyncTest "test":
echo "\nstart"
let res = jobs.awaitSpawn addNums(jobs.queue, 1.0, 2.0)
let res = jobs.awaitJob addNums(jobs.queue, 1.0, 2.0)
# await sleepAsync(100.milliseconds)
echo "result: ", res.repr