From 2bcc3e62d1034193c90ef2f84c972b52df7b2961 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Thu, 15 Feb 2024 00:43:01 -0700 Subject: [PATCH] reworking seq holder --- src/apatheia/jobs.nim | 12 +++++++++--- tests/tjobs.nim | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/apatheia/jobs.nim b/src/apatheia/jobs.nim index 7b8b09d..5fecd86 100644 --- a/src/apatheia/jobs.nim +++ b/src/apatheia/jobs.nim @@ -76,22 +76,28 @@ proc newJobQueue*[T](maxItems: int = 0, taskpool: Taskpool = Taskpool.new()): Jo result = JobQueue[T](queue: newSignalQueue[(uint, T)](maxItems), taskpool: taskpool, running: true) asyncSpawn(processJobs(result)) -template checkJobArgs*[T](exp: seq[T]): OpenArrayHolder[T] = +template checkJobArgs*[T](exp: seq[T], fut: untyped): OpenArrayHolder[T] = # static: # echo "checkJobArgs::SEQ: ", $typeof(exp) let rval = SeqHolder[T](data: exp) + GC_ref(rval) let expPtr = OpenArrayHolder[T](data: cast[ptr UncheckedArray[T]](unsafeAddr(rval.data[0])), size: rval.data.len()) # defer: # ## try and keep the value type # discard val.len() + fut.addCallback proc(data: pointer) = + GC_unref(rval) + echo "FREE RVaL: " + ## TODO: how to handle cancellations? expPtr -template checkJobArgs*(exp: typed): auto = +template checkJobArgs*(exp: typed, fut: untyped): auto = # static: # echo "checkJobArgs:: ", $typeof(exp) exp + macro submitMacro(tp: untyped, jobs: untyped, exp: untyped): untyped = ## modifies the call expression to include the job queue and ## the job id parameters @@ -106,7 +112,7 @@ macro submitMacro(tp: untyped, jobs: untyped, exp: untyped): untyped = var fncall = nnkCall.newTree(exp[0]) fncall.add(jobRes) for p in exp[1..^1]: - fncall.add(nnkCall.newTree(ident"checkJobArgs", p)) + fncall.add(nnkCall.newTree(ident"checkJobArgs", p, `futName`)) result = quote do: block: diff --git a/tests/tjobs.nim b/tests/tjobs.nim index 392755f..02ee070 100644 --- a/tests/tjobs.nim +++ b/tests/tjobs.nim @@ -43,6 +43,6 @@ suite "async tests": asyncTest "testing arrays": var jobs = newJobQueue[float](taskpool = tp) - let res = await jobs.submit(addNumValues(@[1.0, 2.0])) - check res == 3.0 + let res = await jobs.submit(addNumValues(10.0, @[1.0.float, 2.0])) + check res == 13.0