more expers

This commit is contained in:
Jaremy Creechley 2024-02-09 19:17:50 -07:00
parent c0499f8db8
commit 6fba03afa5
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 38 additions and 1 deletions

View File

@ -21,4 +21,3 @@ proc new*[T](tp: typedesc[AsyncQueue[T]]): AsyncQueue[T] {.raises: [ApatheiaSign
else:
result.signal = res.get()

38
tests/tasyncsEx2.nim Normal file
View File

@ -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