mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-03-04 01:50:36 +00:00
11 lines
297 B
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)
|