mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-02 13:03:11 +00:00
adds string support
This commit is contained in:
parent
2b0219e689
commit
9f13d4bc35
@ -100,6 +100,14 @@ template checkJobArgs*[T](exp: seq[T], fut: untyped): OpenArrayHolder[T] =
|
||||
else:
|
||||
{.error: "unsupported sequence type for job argument: " & $typeof(seq[T]).}
|
||||
|
||||
template checkJobArgs*(exp: string, fut: untyped): OpenArrayHolder[char] =
|
||||
let rval = StrRetainer(data: exp)
|
||||
retainMemory(fut.jobId(), rval)
|
||||
let expPtr = OpenArrayHolder[char](
|
||||
data: cast[ptr UncheckedArray[char]](unsafeAddr(rval.data[0])), size: rval.data.len()
|
||||
)
|
||||
expPtr
|
||||
|
||||
template checkJobArgs*(exp: typed, fut: untyped): auto =
|
||||
exp
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ type
|
||||
SeqRetainer*[T] = ref object of Retainer
|
||||
data*: seq[T]
|
||||
|
||||
StrRetainer*[T] = ref object of Retainer
|
||||
StrRetainer* = ref object of Retainer
|
||||
data*: string
|
||||
|
||||
var memoryRetainerTable = newTable[uint, seq[Retainer]]()
|
||||
|
||||
@ -28,6 +28,9 @@ proc addNumValues(jobResult: JobResult[float], base: float, vals: OpenArrayHolde
|
||||
res += x
|
||||
discard jobResult.queue.send((jobResult.id, res,))
|
||||
|
||||
proc strCompute(jobResult: JobResult[int], vals: OpenArrayHolder[char]) =
|
||||
discard jobResult.queue.send((jobResult.id, vals.size,))
|
||||
|
||||
proc addStrings(jobResult: JobResult[float], vals: OpenArrayHolder[string]) =
|
||||
discard
|
||||
|
||||
@ -45,11 +48,16 @@ suite "async tests":
|
||||
|
||||
check res == 3.0
|
||||
|
||||
asyncTest "testing arrays":
|
||||
asyncTest "testing seq":
|
||||
var jobs = newJobQueue[float](taskpool = tp)
|
||||
let res = await jobs.submit(addNumValues(10.0, @[1.0.float, 2.0]))
|
||||
check res == 13.0
|
||||
|
||||
asyncTest "testing string":
|
||||
var jobs = newJobQueue[int](taskpool = tp)
|
||||
let res = await jobs.submit(strCompute("hello world!"))
|
||||
check res == 12
|
||||
|
||||
asyncTest "testing arrays":
|
||||
var jobs = newJobQueue[float](taskpool = tp)
|
||||
let fut1 = jobs.submit(addNumValues(10.0, @[1.0.float, 2.0]))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user