apatheia/tests/tqueues.nim
Jaremy Creechley fb3a50e0e7
rename queue
2024-02-09 21:53:14 -07:00

37 lines
764 B
Nim

import std/os
import chronos
import chronos/threadsync
import chronos/unittest2/asynctests
import taskpools
import apatheia/queues
## todo: setup basic async + threadsignal + taskpools example here
##
proc addNums(a, b: float, queue: SignalQueue[float]) =
os.sleep(500)
echo "adding: ", a, " + ", b
discard queue.send(a + b)
suite "async tests":
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
var queue = newSignalQueue[float]()
asyncTest "test":
echo "\nstart"
tp.spawn addNums(1.0, 2.0, queue)
# await sleepAsync(100.milliseconds)
echo "waiting on queue"
let res = await wait(queue).wait(1500.milliseconds)
echo "result: ", res
# echo "\nRES: ", args.value
check true