mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-05 07:03:12 +00:00
result types
This commit is contained in:
parent
36e6679a79
commit
cfc743ce94
@ -202,7 +202,7 @@ method put*(self: ThreadDatastore,
|
||||
let data = DataBuffer.new data
|
||||
dispatchTask[void](self, signal):
|
||||
self.tp.spawn putTask(ctx, ds, key, data)
|
||||
return ctx[].res
|
||||
return ctx[].res.toRes()
|
||||
|
||||
method put*(
|
||||
self: ThreadDatastore,
|
||||
@ -231,7 +231,8 @@ method get*(self: ThreadDatastore,
|
||||
let key = KeyId.new key.id()
|
||||
dispatchTask[DataBuffer](self, signal):
|
||||
self.tp.spawn getTask(ctx, ds, key)
|
||||
# return ctx[].res
|
||||
return ctx[].res.toRes() do(v: DataBuffer) -> seq[byte]:
|
||||
v.toSeq()
|
||||
|
||||
method close*(self: ThreadDatastore): Future[?!void] {.async.} =
|
||||
await self.semaphore.closeAll()
|
||||
|
||||
@ -40,6 +40,12 @@ converter toExc*(e: ThreadResErr): ref CatchableError =
|
||||
of ErrorEnum.CatchableErr: (ref CatchableError)(msg: $e[1])
|
||||
of ErrorEnum.DefectErr: (ref CatchableError)(msg: "defect: " & $e[1])
|
||||
|
||||
converter toExcRes*[T](res: ThreadResult[T]): ?!T =
|
||||
res.mapErr() do(exc: ThreadResErr) -> ref CatchableError:
|
||||
exc.toExc()
|
||||
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 =
|
||||
if res.isErr():
|
||||
result.err res.error().toExc()
|
||||
else:
|
||||
result.ok m(res.get())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user