compile output test

This commit is contained in:
Jaremy Creechley 2024-02-15 00:16:03 -07:00
parent 91663d9b8f
commit 498b3413fa
2 changed files with 17 additions and 9 deletions

View File

@ -74,17 +74,18 @@ proc newJobQueue*[T](maxItems: int = 0, taskpool: Taskpool = Taskpool.new()): Jo
asyncSpawn(processJobs(result))
template checkJobArgs*[T](exp: seq[T]): OpenArrayHolder[T] =
static:
echo "checkJobArgs::SEQ: ", $typeof(exp)
let val = exp
# static:
# echo "checkJobArgs::SEQ: ", $typeof(exp)
var val = exp # evaluate once
let expPtr = OpenArrayHolder[T](data: cast[ptr UncheckedArray[T]](unsafeAddr(val[0])), size: val.len())
defer:
## try and keep the value type
discard val.len()
expPtr
template checkJobArgs*(exp: typed): auto =
static:
echo "checkJobArgs:: ", $typeof(exp)
# static:
# echo "checkJobArgs:: ", $typeof(exp)
exp
macro submitMacro(tp: untyped, jobs: untyped, exp: untyped): untyped =

View File

@ -20,6 +20,13 @@ proc addNums(jobResult: JobResult[float], a, b: float) =
proc addNumsIncorrect(jobResult: JobResult[float], vals: openArray[float]): float =
discard
proc addNumValues(jobResult: JobResult[float], base: float, vals: OpenArrayHolder[float]) =
os.sleep(100)
var res = base
for x in vals.toOpenArray():
res += x
discard jobResult.queue.send((jobResult.id, res,))
suite "async tests":
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
@ -34,8 +41,8 @@ suite "async tests":
check res == 3.0
# asyncTest "test":
# var jobs = newJobQueue[float](taskpool = tp)
# let res = await jobs.submit(addNumValues([1.0, 2.0]))
# check res == 3.0
asyncTest "testing arrays":
var jobs = newJobQueue[float](taskpool = tp)
let res = await jobs.submit(addNumValues(@[1.0, 2.0]))
check res == 3.0