mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-02 13:03:11 +00:00
docs
This commit is contained in:
parent
78562d367a
commit
dbaebc26fe
@ -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: [].} =
|
proc send*[T](c: SignalQueue[T], msg: sink T): Result[void, string] {.raises: [].} =
|
||||||
## Sends a message to a thread. `msg` is copied.
|
## Sends a message to a thread. `msg` is copied.
|
||||||
|
## Note: currently non-blocking but future iterations may become blocking.
|
||||||
|
##
|
||||||
try:
|
try:
|
||||||
c.chan[].send(msg)
|
c.chan[].send(msg)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@ -47,21 +49,26 @@ proc send*[T](c: SignalQueue[T], msg: sink T): Result[void, string] {.raises: []
|
|||||||
result = ok()
|
result = ok()
|
||||||
|
|
||||||
proc trySend*[T](c: SignalQueue[T], msg: sink T): bool =
|
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)
|
result = c.chan.trySend(msg)
|
||||||
if result:
|
if result:
|
||||||
c.signal.fireSync()
|
c.signal.fireSync()
|
||||||
|
|
||||||
proc recv*[T](c: SignalQueue[T]): Result[T, string] =
|
proc recv*[T](c: SignalQueue[T]): Result[T, string] =
|
||||||
|
## Receive item from queue, blocking.
|
||||||
try:
|
try:
|
||||||
result = ok c.chan[].recv()
|
result = ok c.chan[].recv()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
result = err exc.msg
|
result = err exc.msg
|
||||||
|
|
||||||
proc tryRecv*[T](c: SignalQueue[T]): Option[T] =
|
proc tryRecv*[T](c: SignalQueue[T]): Option[T] =
|
||||||
|
## Try to receive item from queue, non-blocking.
|
||||||
let res = c.chan.recv()
|
let res = c.chan.recv()
|
||||||
if res.dataAvailable:
|
if res.dataAvailable:
|
||||||
some res.msg
|
some res.msg
|
||||||
|
|
||||||
proc wait*[T](c: SignalQueue[T]): Future[Result[T, string]] {.async.} =
|
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)
|
await wait(c.signal)
|
||||||
return c.recv()
|
return c.recv()
|
||||||
|
|||||||
@ -9,11 +9,6 @@ import taskpools
|
|||||||
import apatheia/queues
|
import apatheia/queues
|
||||||
import apatheia/jobs
|
import apatheia/jobs
|
||||||
|
|
||||||
## todo: setup basic async + threadsignal + taskpools example here
|
|
||||||
##
|
|
||||||
|
|
||||||
import std/macros
|
|
||||||
|
|
||||||
proc addNumsRaw(a, b: float): float =
|
proc addNumsRaw(a, b: float): float =
|
||||||
os.sleep(50)
|
os.sleep(50)
|
||||||
return a + b
|
return a + b
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user