mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-03 13:33:08 +00:00
initial setup
This commit is contained in:
parent
a8ebb17dc8
commit
3995c73974
@ -8,11 +8,30 @@ import taskpools
|
||||
|
||||
import apatheia/queues
|
||||
|
||||
type
|
||||
DataObj = ref object
|
||||
data: seq[char]
|
||||
|
||||
proc worker(data: seq[char], queue: SignalQueue[int]) =
|
||||
os.sleep(50)
|
||||
os.sleep(5000)
|
||||
echo "worker: ", data
|
||||
discard queue.send(data.len())
|
||||
|
||||
proc finalizer(obj: DataObj) =
|
||||
echo "FINALIZE!!"
|
||||
|
||||
proc runTest(tp: TaskPool, queue: SignalQueue[int]) {.async.} =
|
||||
## init
|
||||
var data = "hello world!".toSeq
|
||||
var obj: DataObj
|
||||
new(obj, finalizer)
|
||||
|
||||
echo "spawn worker"
|
||||
tp.spawn worker(data, queue)
|
||||
|
||||
let res = await wait(queue)
|
||||
check res.get() == 12
|
||||
|
||||
suite "async tests":
|
||||
|
||||
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
|
||||
@ -20,11 +39,8 @@ suite "async tests":
|
||||
|
||||
asyncTest "test":
|
||||
|
||||
## init
|
||||
var data = "hello world!".toSeq
|
||||
tp.spawn worker(data, queue)
|
||||
|
||||
let res = await wait(queue)
|
||||
check res.get() == 12
|
||||
await runTest(tp, queue)
|
||||
GC_fullCollect()
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user