mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-02 21:13:08 +00:00
43 lines
1.0 KiB
Nim
43 lines
1.0 KiB
Nim
import std/os
|
|
|
|
import chronos
|
|
import chronos/threadsync
|
|
import chronos/unittest2/asynctests
|
|
import taskpools
|
|
|
|
import apatheia/queues
|
|
import apatheia/tasks
|
|
|
|
## todo: setup basic async + threadsignal + taskpools example here
|
|
##
|
|
|
|
proc addNums(a, b: float): float {.asyncTask.} =
|
|
os.sleep(100)
|
|
echo "adding: ", a, " + ", b
|
|
return a + b
|
|
|
|
proc addNumValues(vals: openArray[float]): float {.asyncTask.} =
|
|
os.sleep(100)
|
|
result = 0.0
|
|
for x in vals:
|
|
result += x
|
|
echo "adding sums: ", vals
|
|
|
|
suite "async tests":
|
|
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
|
|
|
|
asyncTest "test addNums":
|
|
var jobs = newJobQueue[float](taskpool = tp)
|
|
echo "\nstart"
|
|
let res = await jobs.submit(addNums(1.0, 2.0,))
|
|
echo "result: ", res.repr
|
|
check true
|
|
|
|
asyncTest "test addNumValues":
|
|
var jobs = newJobQueue[float](taskpool = tp)
|
|
echo "\nstart"
|
|
let args = @[1.0, 2.0, 3.0]
|
|
let res = await jobs.submit(addNumValues(args))
|
|
echo "result: ", res.repr
|
|
check true
|