From 34df48f36976a2b4b1be0c55dae63c1a1b589c53 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Fri, 16 Feb 2024 15:07:11 -0700 Subject: [PATCH] docs --- src/apatheia/tasks.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/apatheia/tasks.nim b/src/apatheia/tasks.nim index e0d67f1..e970f35 100644 --- a/src/apatheia/tasks.nim +++ b/src/apatheia/tasks.nim @@ -8,6 +8,24 @@ export jobs ## Tasks provide a convenience wrapper for using the jobs module. It also ## provides some extra conveniences like handling a subset of `openArray[T]` ## types in a safe manner using `OpenArrayHolder[T]` type. +## +## The `asyncTask` macro works by creating a wrapper proc around the +## annotated user proc. The transformation looks similar to: +## +## .. code-block:: +## proc doHashes*(data: openArray[byte], opts: HashOptions): float {.asyncTask.} = +## result = 10.0 + +## +## .. code-block:: +## proc doHashesTasklet*(data: openArray[byte]; opts: HashOptions): float {.nimcall.} = +## result = 10.0 +## +## proc doHashes*(jobResult: JobResult[float]; data: OpenArrayHolder[byte]; +## opts: HashOptions) {.nimcall.} = +## let val {.inject.} = doHashesTasklet(convertParamType(data), +## convertParamType(opts)) +## discard jobResult.queue.send((jobResult.id, val)) template convertParamType*[T](obj: OpenArrayHolder[T]): auto = static: @@ -83,3 +101,4 @@ when isMainModule: proc doHashes*(data: openArray[byte], opts: HashOptions): float {.asyncTask.} = echo "hashing" + result = 10.0