mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-02 13:03:11 +00:00
41 lines
821 B
Nim
41 lines
821 B
Nim
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
|
|
|