combining together

This commit is contained in:
Jaremy Creechley 2024-02-13 22:20:54 -07:00
parent ab7881ed4c
commit 4a039ec5cd
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
4 changed files with 16 additions and 13 deletions

View File

@ -121,11 +121,11 @@ proc identPub*(name: string): NimNode =
result = nnkPostfix.newTree(newIdentNode("*"), ident name)
proc procIdentAppend*(id: NimNode, name: string): NimNode =
result = id.copyNimTree()
if id.kind == nnkPostfix:
result = id
result[1] = ident(result[1].strVal & name)
else:
result = ident(result.strVal & name)
result = ident(id.strVal & name)
proc mkCall*(callName, params: NimNode): NimNode =
## Create local variables for each parameter in the actual RPC call proc
@ -143,4 +143,4 @@ proc mkProc*(name, params, body: NimNode): NimNode =
`body`
result[3].del(0)
for arg in args:
result[3].add arg
result.params.add arg

View File

@ -29,20 +29,22 @@ macro asyncTask*(p: untyped): untyped =
echo "name: ", name
# echo "ASYNC_TASK: call: \n", tcall.treeRepr
var asyncBody = newStmtList()
for paramId, paramType in paramsIter(params):
echo "param: ", paramId, " tp: ", paramType.treeRepr
asyncBody.add newCall("checkParamType", paramId)
let tcall = mkCall(ident name, params)
# echo "asyncTask:checks:\n", asyncBody.repr
# echo "asyncTask:tcall: ", tcall.repr
echo "asyncTask:body:\n", body.repr
let tp = mkProc(procId.procIdentAppend("Tasklet"),
params, body)
var asyncBody = newStmtList()
let tcall = newCall(ident name)
for paramId, paramType in paramsIter(params):
echo "param: ", paramId, " tp: ", paramType.treeRepr
tcall.add newCall("checkParamType", paramId)
asyncBody.add tcall
let fn = mkProc(procId, params, asyncBody)
# echo "asyncTask:fn:body:\n", fn.treerepr
result = newStmtList()
result.add tp
result.add fn
echo "asyncTask:body:\n", result.repr
# echo "asyncTask:body:\n", result.treeRepr

View File

@ -32,7 +32,7 @@ suite "async tests":
var jobs = newJobQueue[float](taskpool = tp)
echo "\nstart"
let res = await jobs.submit(addNums(1.0, 2.0,))
let res = await jobs.submit(addNums2(1.0, 2.0,))
# await sleepAsync(100.milliseconds)
echo "result: ", res.repr

View File

@ -11,6 +11,7 @@ import apatheia/tasks
## todo: setup basic async + threadsignal + taskpools example here
##
proc addNums(a, b: float): float {.asyncTask.} =
os.sleep(500)
echo "adding: ", a, " + ", b