From dbaebc26fe3f7a96b6195b86654cc08125a15c39 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Wed, 14 Feb 2024 22:07:35 -0700 Subject: [PATCH] docs --- src/apatheia/queues.nim | 7 +++++++ tests/tjobs.nim | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/apatheia/queues.nim b/src/apatheia/queues.nim index 6112326..9efbcec 100644 --- a/src/apatheia/queues.nim +++ b/src/apatheia/queues.nim @@ -35,6 +35,8 @@ proc newSignalQueue*[T](maxItems: int = 0): SignalQueue[T] {.raises: [ApatheiaSi proc send*[T](c: SignalQueue[T], msg: sink T): Result[void, string] {.raises: [].} = ## Sends a message to a thread. `msg` is copied. + ## Note: currently non-blocking but future iterations may become blocking. + ## try: c.chan[].send(msg) except Exception as exc: @@ -47,21 +49,26 @@ proc send*[T](c: SignalQueue[T], msg: sink T): Result[void, string] {.raises: [] result = ok() proc trySend*[T](c: SignalQueue[T], msg: sink T): bool = + ## Trys to sends a message to a thread. `msg` is copied. Non-blocking. result = c.chan.trySend(msg) if result: c.signal.fireSync() proc recv*[T](c: SignalQueue[T]): Result[T, string] = + ## Receive item from queue, blocking. try: result = ok c.chan[].recv() except Exception as exc: result = err exc.msg proc tryRecv*[T](c: SignalQueue[T]): Option[T] = + ## Try to receive item from queue, non-blocking. let res = c.chan.recv() if res.dataAvailable: some res.msg proc wait*[T](c: SignalQueue[T]): Future[Result[T, string]] {.async.} = + ## Async compatible receive from queue. Pauses async execution until + ## an item is received from the queue await wait(c.signal) return c.recv() diff --git a/tests/tjobs.nim b/tests/tjobs.nim index deb3296..933686f 100644 --- a/tests/tjobs.nim +++ b/tests/tjobs.nim @@ -9,11 +9,6 @@ import taskpools import apatheia/queues import apatheia/jobs -## todo: setup basic async + threadsignal + taskpools example here -## - -import std/macros - proc addNumsRaw(a, b: float): float = os.sleep(50) return a + b