mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-31 03:33:08 +00:00
add option to result converter
This commit is contained in:
parent
af0741b879
commit
07f38097d6
@ -7,6 +7,8 @@
|
||||
## This file may not be copied, modified, or distributed except according to
|
||||
## those terms.
|
||||
|
||||
import std/options
|
||||
|
||||
import pkg/stew/results
|
||||
import pkg/chronos
|
||||
import pkg/questionable/results
|
||||
@ -29,6 +31,12 @@ template mapFailure*[T, V, E](
|
||||
template mapFailure*[T, V](exp: Result[T, V]): Result[T, ref CatchableError] =
|
||||
mapFailure(exp, CodexError)
|
||||
|
||||
template toResult*[T](exp: Option[T]): Result[T, ref CatchableError] =
|
||||
if exp.isSome:
|
||||
success exp.get
|
||||
else:
|
||||
T.failure("Option is None")
|
||||
|
||||
proc allFutureResult*[T](fut: seq[Future[T]]): Future[?!void] {.async.} =
|
||||
try:
|
||||
await allFuturesThrowing(fut)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user