mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-04 14:03:09 +00:00
more expers
This commit is contained in:
parent
c0499f8db8
commit
6fba03afa5
@ -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
38
tests/tasyncsEx2.nim
Normal 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user