2024-08-07 21:05:33 +02:00
|
|
|
import chronos/futures, stew/results, chronos
|
|
|
|
|
|
|
|
proc waitForResult*[T](
|
2024-08-23 18:42:13 +02:00
|
|
|
fut: Future[T], timeout: Duration = 1.seconds
|
2024-08-07 21:05:33 +02:00
|
|
|
): 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)
|
2024-08-23 18:42:13 +02:00
|
|
|
|
|
|
|
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)
|