result types

This commit is contained in:
Jaremy Creechley 2023-09-26 17:23:42 -07:00
parent cfc743ce94
commit e75081f832
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 6 additions and 3 deletions

View File

@ -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()

View File

@ -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: