From 14d65a506069d5e112aeccdeef82ee9989788311 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Tue, 13 Feb 2024 22:36:25 -0700 Subject: [PATCH] combining together --- src/apatheia/tasks.nim | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/apatheia/tasks.nim b/src/apatheia/tasks.nim index 0e57df2..754e401 100644 --- a/src/apatheia/tasks.nim +++ b/src/apatheia/tasks.nim @@ -33,20 +33,23 @@ macro asyncTask*(p: untyped): untyped = params, body) var asyncBody = newStmtList() - let tcall = newCall(ident name) + let tcall = newCall(ident(name & "Tasklet")) for paramId, paramType in paramsIter(params): echo "param: ", paramId, " tp: ", paramType.treeRepr tcall.add newCall("checkParamType", paramId) - asyncBody.add tcall + asyncBody.add quote do: + let res = `tcall` var asyncParams = params.copyNimTree() let retType = if not hasReturnType(params): ident"void" else: params.getReturnType() - echo "RETTYPE: ", retType.repr - # let jobRes = genSym(nskLet, "jobRes") - # asyncParams.insert(0, ) + let jobArg = nnkIdentDefs.newTree( + ident"jobResult", + nnkBracketExpr.newTree(ident"JobResult", retType), + newEmptyNode() + ) + asyncParams.insert(1, jobArg) let fn = mkProc(procId, asyncParams, asyncBody) - # echo "asyncTask:fn:body:\n", fn.treerepr result = newStmtList() @@ -61,11 +64,11 @@ type proc doHashes*(data: openArray[byte], opts: HashOptions) {.asyncTask.} = - discard + echo "hashing" proc doHashes2*(data: openArray[byte], opts: HashOptions): float {.asyncTask.} = - discard + echo "hashing" # proc doHashesRes*(data: openArray[byte], # opts: HashOptions): int {.asyncTask.} =