mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-07 15:33:09 +00:00
refactor
This commit is contained in:
parent
2ac09d1e2c
commit
898c7bce8c
@ -77,17 +77,16 @@ proc newJobQueue*[T](maxItems: int = 0, taskpool: Taskpool = Taskpool.new()): Jo
|
|||||||
asyncSpawn(processJobs(result))
|
asyncSpawn(processJobs(result))
|
||||||
|
|
||||||
template checkJobArgs*[T](exp: seq[T], fut: untyped): OpenArrayHolder[T] =
|
template checkJobArgs*[T](exp: seq[T], fut: untyped): OpenArrayHolder[T] =
|
||||||
# static:
|
when T is byte | SomeInteger | SomeFloat:
|
||||||
# echo "checkJobArgs::SEQ: ", $typeof(exp)
|
let rval = SeqHolder[T](data: exp)
|
||||||
let rval = SeqHolder[T](data: exp)
|
fut.jobId().retainMemory(rval)
|
||||||
fut.jobId().retainMemory(rval)
|
let expPtr = OpenArrayHolder[T](data: cast[ptr UncheckedArray[T]](unsafeAddr(rval.data[0])), size: rval.data.len())
|
||||||
let expPtr = OpenArrayHolder[T](data: cast[ptr UncheckedArray[T]](unsafeAddr(rval.data[0])), size: rval.data.len())
|
expPtr
|
||||||
expPtr
|
else:
|
||||||
|
{.error: "unsupported sequence type for job argument: " & $typeof(seq[T]).}
|
||||||
|
|
||||||
|
|
||||||
template checkJobArgs*(exp: typed, fut: untyped): auto =
|
template checkJobArgs*(exp: typed, fut: untyped): auto =
|
||||||
# static:
|
|
||||||
# echo "checkJobArgs:: ", $typeof(exp)
|
|
||||||
exp
|
exp
|
||||||
|
|
||||||
|
|
||||||
@ -115,9 +114,6 @@ macro submitMacro(tp: untyped, jobs: untyped, exp: untyped): untyped =
|
|||||||
fncall.add(jobRes)
|
fncall.add(jobRes)
|
||||||
for p in argids:
|
for p in argids:
|
||||||
fncall.add(p)
|
fncall.add(p)
|
||||||
# for p in exp[1..^1]:
|
|
||||||
# echo "CHECK ARGS: ", p.treeRepr
|
|
||||||
# fncall.add(nnkCall.newTree(ident"checkJobArgs", p, `futName`))
|
|
||||||
|
|
||||||
result = quote do:
|
result = quote do:
|
||||||
block:
|
block:
|
||||||
@ -149,11 +145,14 @@ when isMainModule:
|
|||||||
res += x
|
res += x
|
||||||
discard jobResult.queue.send((jobResult.id, res,))
|
discard jobResult.queue.send((jobResult.id, res,))
|
||||||
|
|
||||||
|
proc addStrings(jobResult: JobResult[float], vals: OpenArrayHolder[string]) =
|
||||||
|
discard
|
||||||
|
|
||||||
suite "async tests":
|
suite "async tests":
|
||||||
|
|
||||||
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
|
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
|
||||||
|
|
||||||
asyncTest "test":
|
asyncTest "basic openarray":
|
||||||
# expandMacros:
|
# expandMacros:
|
||||||
var jobs = newJobQueue[float](taskpool = tp)
|
var jobs = newJobQueue[float](taskpool = tp)
|
||||||
|
|
||||||
@ -161,3 +160,12 @@ when isMainModule:
|
|||||||
let res = await job
|
let res = await job
|
||||||
|
|
||||||
check res == 13.0
|
check res == 13.0
|
||||||
|
|
||||||
|
asyncTest "don't compile":
|
||||||
|
# expandMacros:
|
||||||
|
var jobs = newJobQueue[float](taskpool = tp)
|
||||||
|
|
||||||
|
let job = jobs.submit(addStrings(@["a", "b", "c"]))
|
||||||
|
let res = await job
|
||||||
|
|
||||||
|
check res == 13.0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user