apatheia/tests/tqueues.nim

29 lines
539 B
Nim
Raw Normal View History

2024-02-09 19:17:50 -07:00
import std/os
import chronos
import chronos/threadsync
import chronos/unittest2/asynctests
import taskpools
2024-02-09 21:25:34 -07:00
import apatheia/queues
2024-02-09 21:44:07 -07:00
proc addNums(a, b: float, queue: SignalQueue[float]) =
2024-02-14 22:02:46 -07:00
os.sleep(50)
2024-02-09 21:44:07 -07:00
discard queue.send(a + b)
2024-02-09 19:17:50 -07:00
suite "async tests":
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
2024-02-09 21:44:07 -07:00
var queue = newSignalQueue[float]()
2024-02-09 19:17:50 -07:00
asyncTest "test":
2024-02-14 21:53:02 -07:00
## init
tp.spawn addNums(1.0, 2.0, queue)
2024-02-09 21:44:07 -07:00
2024-02-09 21:52:37 -07:00
let res = await wait(queue).wait(1500.milliseconds)
2024-02-09 19:17:50 -07:00
2024-02-14 21:53:02 -07:00
check res.get() == 3.0
2024-02-09 19:17:50 -07:00