diff --git a/tests/expers/tasyncWorkers.nim b/tests/expers/tasyncWorkers.nim deleted file mode 100644 index 16e4a9a..0000000 --- a/tests/expers/tasyncWorkers.nim +++ /dev/null @@ -1,40 +0,0 @@ -import std/os - -import chronos -import chronos/threadsync -import chronos/unittest2/asynctests -import taskpools - -## todo: setup basic async + threadsignal + taskpools example here -## - -var todo: Future[float] - -proc completeAfter() {.async.} = - {.cast(gcsafe).}: - await sleepAsync(500.milliseconds) - echo "completing result: " - todo.complete(4.0) - -proc addNums(a, b: float): Future[float] = - {.cast(gcsafe).}: - let fut = newFuture[float]("addNums") - todo = fut - result = fut - -suite "async tests": - - # var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads. - - asyncTest "test": - - # await sleepAsync(100.milliseconds) - let fut = addNums(1, 3) - asyncSpawn completeAfter() - echo "\nawaiting result: " - let res = await fut - - echo "\nRES: ", res - - check true - diff --git a/tests/expers/tasyncsEx1.nim b/tests/expers/tasyncsEx1.nim deleted file mode 100644 index 4803d91..0000000 --- a/tests/expers/tasyncsEx1.nim +++ /dev/null @@ -1,40 +0,0 @@ -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 - startSig: ThreadSignalPtr - 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.startSig = ThreadSignalPtr.new().get() - 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 - diff --git a/tests/expers/test1.nim b/tests/expers/test1.nim deleted file mode 100644 index 34a96e9..0000000 --- a/tests/expers/test1.nim +++ /dev/null @@ -1,13 +0,0 @@ -# This is just an example to get you started. You may wish to put all of your -# tests into a single file, or separate them into multiple `test1`, `test2` -# etc. files (better names are recommended, just make sure the name starts with -# the letter 't'). -# -# To run these tests, simply execute `nimble test`. - -import unittest - -import apatheia/tasks - -test "can add": - check 10 == 10 diff --git a/tests/expers/tpoolsEx1.nim b/tests/expers/tpoolsEx1.nim deleted file mode 100644 index 9678de4..0000000 --- a/tests/expers/tpoolsEx1.nim +++ /dev/null @@ -1,33 +0,0 @@ - -import std/[strutils, math, cpuinfo] - -import taskpools - -# From https://github.com/nim-lang/Nim/blob/v1.6.2/tests/parallel/tpi.nim -# Leibniz Formula https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80 -proc term(k: int): float = - if k mod 2 == 1: - -4'f / float(2*k + 1) - else: - 4'f / float(2*k + 1) - -proc piApprox(tp: Taskpool, n: int): float = - var pendingFuts = newSeq[FlowVar[float]](n) - for k in 0 ..< pendingFuts.len: - pendingFuts[k] = tp.spawn term(k) # Schedule a task on the threadpool a return a handle to retrieve the result. - for k in 0 ..< pendingFuts.len: - result += sync pendingFuts[k] # Block until the result is available. - -proc main() = - var n = 1_000 - var nthreads = countProcessors() - - var tp = Taskpool.new(num_threads = nthreads) # Default to the number of hardware threads. - - echo formatFloat(tp.piApprox(n)) - - tp.syncAll() # Block until all pending tasks are processed (implied in tp.shutdown()) - tp.shutdown() - -# Compile with nim c -r -d:release --threads:on --outdir:build example.nim -main()