diff --git a/src/apatheia/queues.nim b/src/apatheia/queues.nim index e607ec3..f72df84 100644 --- a/src/apatheia/queues.nim +++ b/src/apatheia/queues.nim @@ -21,4 +21,3 @@ proc new*[T](tp: typedesc[AsyncQueue[T]]): AsyncQueue[T] {.raises: [ApatheiaSign else: result.signal = res.get() - diff --git a/tests/tasyncsEx2.nim b/tests/tasyncsEx2.nim new file mode 100644 index 0000000..d5a866c --- /dev/null +++ b/tests/tasyncsEx2.nim @@ -0,0 +1,38 @@ +import std/os + +import chronos +import chronos/threadsync +import chronos/unittest2/asynctests +import taskpools + +## todo: setup basic async + threadsignal + taskpools example here +## + +type + ThreadArg = object + doneSig: ThreadSignalPtr + value: float + +proc addNums(a, b: float, ret: ptr ThreadArg) = + ret.value = a + b + os.sleep(500) + let res = ret.doneSig.fireSync().get() + if not res: + echo "ERROR FIRING!" + +suite "async tests": + + var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads. + + asyncTest "test": + var args = ThreadArg() + args.doneSig = ThreadSignalPtr.new().get() + + tp.spawn addNums(1, 2, addr args) + # await sleepAsync(100.milliseconds) + await wait(args.doneSig).wait(1500.milliseconds) + + echo "\nRES: ", args.value + + check true +