mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-01-20 18:00:04 +00:00
Update waitForResult to handle void futures.
This commit is contained in:
parent
f791e78cda
commit
56419460ae
@ -1,10 +1,19 @@
|
||||
import chronos/futures, stew/results, chronos
|
||||
|
||||
proc waitForResult*[T](
|
||||
fut: Future[T], timeout: Duration
|
||||
fut: Future[T], timeout: Duration = 1.seconds
|
||||
): 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)
|
||||
|
||||
proc waitForResult*(
|
||||
fut: Future[void], timeout: Duration = 1.seconds
|
||||
): Future[Result[void, string]] {.async.} =
|
||||
try:
|
||||
await fut.wait(timeout)
|
||||
return Result[void, string].ok()
|
||||
except Exception as e:
|
||||
return Result[void, string].err(e.msg)
|
||||
|
Loading…
x
Reference in New Issue
Block a user