mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-04 05:53:11 +00:00
reworking seq holder
This commit is contained in:
parent
8c35ed16ed
commit
2bcc3e62d1
@ -76,22 +76,28 @@ proc newJobQueue*[T](maxItems: int = 0, taskpool: Taskpool = Taskpool.new()): Jo
|
|||||||
result = JobQueue[T](queue: newSignalQueue[(uint, T)](maxItems), taskpool: taskpool, running: true)
|
result = JobQueue[T](queue: newSignalQueue[(uint, T)](maxItems), taskpool: taskpool, running: true)
|
||||||
asyncSpawn(processJobs(result))
|
asyncSpawn(processJobs(result))
|
||||||
|
|
||||||
template checkJobArgs*[T](exp: seq[T]): OpenArrayHolder[T] =
|
template checkJobArgs*[T](exp: seq[T], fut: untyped): OpenArrayHolder[T] =
|
||||||
# static:
|
# static:
|
||||||
# echo "checkJobArgs::SEQ: ", $typeof(exp)
|
# echo "checkJobArgs::SEQ: ", $typeof(exp)
|
||||||
let rval = SeqHolder[T](data: exp)
|
let rval = SeqHolder[T](data: exp)
|
||||||
|
GC_ref(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())
|
||||||
# defer:
|
# defer:
|
||||||
# ## try and keep the value type
|
# ## try and keep the value type
|
||||||
# discard val.len()
|
# discard val.len()
|
||||||
|
fut.addCallback proc(data: pointer) =
|
||||||
|
GC_unref(rval)
|
||||||
|
echo "FREE RVaL: "
|
||||||
|
## TODO: how to handle cancellations?
|
||||||
expPtr
|
expPtr
|
||||||
|
|
||||||
|
|
||||||
template checkJobArgs*(exp: typed): auto =
|
template checkJobArgs*(exp: typed, fut: untyped): auto =
|
||||||
# static:
|
# static:
|
||||||
# echo "checkJobArgs:: ", $typeof(exp)
|
# echo "checkJobArgs:: ", $typeof(exp)
|
||||||
exp
|
exp
|
||||||
|
|
||||||
|
|
||||||
macro submitMacro(tp: untyped, jobs: untyped, exp: untyped): untyped =
|
macro submitMacro(tp: untyped, jobs: untyped, exp: untyped): untyped =
|
||||||
## modifies the call expression to include the job queue and
|
## modifies the call expression to include the job queue and
|
||||||
## the job id parameters
|
## the job id parameters
|
||||||
@ -106,7 +112,7 @@ macro submitMacro(tp: untyped, jobs: untyped, exp: untyped): untyped =
|
|||||||
var fncall = nnkCall.newTree(exp[0])
|
var fncall = nnkCall.newTree(exp[0])
|
||||||
fncall.add(jobRes)
|
fncall.add(jobRes)
|
||||||
for p in exp[1..^1]:
|
for p in exp[1..^1]:
|
||||||
fncall.add(nnkCall.newTree(ident"checkJobArgs", p))
|
fncall.add(nnkCall.newTree(ident"checkJobArgs", p, `futName`))
|
||||||
|
|
||||||
result = quote do:
|
result = quote do:
|
||||||
block:
|
block:
|
||||||
|
|||||||
@ -43,6 +43,6 @@ suite "async tests":
|
|||||||
|
|
||||||
asyncTest "testing arrays":
|
asyncTest "testing arrays":
|
||||||
var jobs = newJobQueue[float](taskpool = tp)
|
var jobs = newJobQueue[float](taskpool = tp)
|
||||||
let res = await jobs.submit(addNumValues(@[1.0, 2.0]))
|
let res = await jobs.submit(addNumValues(10.0, @[1.0.float, 2.0]))
|
||||||
check res == 3.0
|
check res == 13.0
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user