From 2ed1b2102e61349f4b8713ad00723c47fde50900 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Fri, 16 Feb 2024 14:44:06 -0700 Subject: [PATCH] setup OpenArrayHolder conversion --- src/apatheia/tasks.nim | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/apatheia/tasks.nim b/src/apatheia/tasks.nim index 2e958b2..6bef3bb 100644 --- a/src/apatheia/tasks.nim +++ b/src/apatheia/tasks.nim @@ -10,7 +10,7 @@ export jobs template convertParamType*[T](obj: OpenArrayHolder[T]): auto = static: echo "CONVERTPARAMTYPE:: ", $typeof(obj) - obj + obj.toOpenArray() template convertParamType*(obj: typed): auto = obj @@ -45,7 +45,6 @@ macro asyncTask*(p: untyped): untyped = let val {.inject.} = `tcall` discard jobResult.queue.send((jobResult.id, val)) - var asyncParams = params.copyNimTree() let retType = if not hasReturnType(params): ident"void" @@ -55,8 +54,21 @@ macro asyncTask*(p: untyped): untyped = let jobArg = nnkIdentDefs.newTree( ident"jobResult", nnkBracketExpr.newTree(ident"JobResult", retType), newEmptyNode() ) - asyncParams[0] = newEmptyNode() - asyncParams.insert(1, jobArg) + var asyncParams = nnkFormalParams.newTree() + echo "TASKER: ", asyncParams.treeRepr + asyncParams.add newEmptyNode() + asyncParams.add jobArg + for i, p in params[1..^1]: + echo "TASKER: PARAM: ", p.treeRepr + let pt = p[1] + if pt.kind == nnkBracketExpr and pt[0].repr == "openArray": + echo "TASKER: PARAM: ", "FOUND OPEN PARAM" + p[1] = nnkBracketExpr.newTree(ident"OpenArrayHolder", pt[1]) + asyncParams.add p + else: + asyncParams.add p + + let fn = mkProc(procId, asyncParams, asyncBody) result = newStmtList()