From e75081f832c470c340c9b766a0eee32dfbf997d5 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Tue, 26 Sep 2023 17:23:42 -0700 Subject: [PATCH] result types --- datastore/threads/threadproxyds.nim | 5 +++-- datastore/threads/threadresult.nim | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/datastore/threads/threadproxyds.nim b/datastore/threads/threadproxyds.nim index d77ec49..7d6541d 100644 --- a/datastore/threads/threadproxyds.nim +++ b/datastore/threads/threadproxyds.nim @@ -8,6 +8,8 @@ push: {.upraises: [].} import std/tables import std/locks +import std/sugar + import pkg/chronos import pkg/chronos/threadsync @@ -231,8 +233,7 @@ method get*(self: ThreadDatastore, let key = KeyId.new key.id() dispatchTask[DataBuffer](self, signal): self.tp.spawn getTask(ctx, ds, key) - return ctx[].res.toRes() do(v: DataBuffer) -> seq[byte]: - v.toSeq() + return ctx[].res.toRes(v => v.toSeq()) method close*(self: ThreadDatastore): Future[?!void] {.async.} = await self.semaphore.closeAll() diff --git a/datastore/threads/threadresult.nim b/datastore/threads/threadresult.nim index 7754f12..da0df6d 100644 --- a/datastore/threads/threadresult.nim +++ b/datastore/threads/threadresult.nim @@ -44,7 +44,9 @@ proc toRes*(res: ThreadResult[void]): ?!void = res.mapErr() do(e: ThreadResErr) -> ref CatchableError: e.toExc() -proc toRes*[T,S](res: ThreadResult[T], m: proc(v: T): S = proc(v: T): T = v): ?!S = +proc toRes*[T,S](res: ThreadResult[T], + m: proc(v: T): S = proc(v: T): T = v): ?!S = + # todo: cleaner way to do this? if res.isErr(): result.err res.error().toExc() else: