mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-04 14:43:12 +00:00
result types
This commit is contained in:
parent
cfc743ce94
commit
e75081f832
@ -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()
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user