add option to result converter

This commit is contained in:
Dmitriy Ryajov 2023-12-22 17:16:04 -06:00
parent af0741b879
commit 07f38097d6
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
1 changed files with 8 additions and 0 deletions

View File

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