nim-libp2p/tests/utils/async.nim

11 lines
297 B
Nim

import chronos/futures, stew/results, chronos
proc waitForResult*[T](
fut: Future[T], timeout: Duration
): Future[Result[T, string]] {.async.} =
try:
let val = await fut.wait(timeout)
return Result[T, string].ok(val)
except Exception as e:
return Result[T, string].err(e.msg)