This commit is contained in:
Diego 2024-08-12 12:48:00 +02:00
parent 661d2cea3e
commit 188b119d2e
No known key found for this signature in database
GPG Key ID: C9DAC9BF68D1F806
2 changed files with 8 additions and 3 deletions

View File

@ -33,8 +33,8 @@ proc anyCompleted*[T](futs: seq[Future[T]]): Future[Future[T]] {.async.} =
let index = requests.find(raceFut)
requests.del(index)
proc raceCancel*[T](
futs: seq[Future[T]]
proc raceCancel*(
futs: seq[Future | InternalRaisesFuture]
): Future[void] {.async: (raises: [ValueError, CancelledError]).} =
try:
discard await race(futs)

View File

@ -48,5 +48,10 @@ suite "Utils Future":
asyncTest "raceCancel with AsyncEvent":
let asyncEvent = newAsyncEvent()
let fut1 = asyncEvent.wait()
let fut2 = newAsyncEvent().wait()
asyncEvent.fire()
await raceCancel(@[fut1, fut2])
await raceCancel(@[asyncEvent.wait()])
check fut1.finished
check fut2.cancelled