mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-28 17:53:16 +00:00
updates
This commit is contained in:
parent
51459a8c9b
commit
3a6ef39530
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user