From 98ddd00d625aeb05603cd434fffba2aab8eeb43b Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Fri, 9 Feb 2024 18:55:29 -0700 Subject: [PATCH] queues --- src/apatheia/queues.nim | 10 +++++++--- src/apatheia/types.nim | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/apatheia/queues.nim b/src/apatheia/queues.nim index 04827f7..e607ec3 100644 --- a/src/apatheia/queues.nim +++ b/src/apatheia/queues.nim @@ -1,3 +1,5 @@ +import std/channels + import ./types import chronos @@ -10,11 +12,13 @@ type AsyncQueue*[T] = object signal: ThreadSignalPtr - item*: T + chan*: T -proc new*[T](tp: typedesc[AsyncQueue[T]]): AsyncQueue[T] {.raises: [ApatheiaException].} = +proc new*[T](tp: typedesc[AsyncQueue[T]]): AsyncQueue[T] {.raises: [ApatheiaSignalErr].} = let res = ThreadSignalPtr.new() if res.isErr(): - raise newException(ApatheiaException, msg: res.err()) + raise newException(ApatheiaSignalErr, msg: res.err()) + else: + result.signal = res.get() diff --git a/src/apatheia/types.nim b/src/apatheia/types.nim index 44f93ab..a2a845b 100644 --- a/src/apatheia/types.nim +++ b/src/apatheia/types.nim @@ -1,3 +1,4 @@ type ApatheiaException* = ref object of CatchableError + ApatheiaSignalErr* = ref object of ApatheiaException