From bcaeda748fe44bac75db42e17095f66af20969f4 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Tue, 13 Feb 2024 22:58:27 -0700 Subject: [PATCH] got together --- tests/ttasks.nim | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/ttasks.nim b/tests/ttasks.nim index b995914..32462e2 100644 --- a/tests/ttasks.nim +++ b/tests/ttasks.nim @@ -17,12 +17,27 @@ proc addNums(a, b: float): float {.asyncTask.} = echo "adding: ", a, " + ", b return a + b +proc addNumValues(vals: openArray[float]): float {.asyncTask.} = + os.sleep(500) + 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": - var jobs = newJobQueue[float](taskpool = tp) + 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