mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-07 15:33:09 +00:00
combining together
This commit is contained in:
parent
ab7881ed4c
commit
4a039ec5cd
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user