Update waitForResult to handle void futures.

This commit is contained in:
Alejandro Cabeza Romero 2024-08-23 18:42:13 +02:00
parent f791e78cda
commit 56419460ae
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD

View File

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