Commit a6e45d6 1 parent 37e0f61 commit a6e45d6 Copy full SHA for a6e45d6
File tree 1 file changed +10
-6
lines changed
1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -13,21 +13,25 @@ import chronos
13
13
14
14
type AllFuturesFailedError * = object of CatchableError
15
15
16
- proc anyCompleted * [T](futs: seq [Future [T]]): Future [Future [T]] {.async .} =
16
+ proc anyCompleted * [T](
17
+ futs: seq [Future [T]]
18
+ ): Future [Future [T]] {.async : (raises: [AllFuturesFailedError , CancelledError ]).} =
17
19
# # Returns a future that will complete with the first future that completes.
18
20
# # If all futures fail or futs is empty, the returned future will fail with AllFuturesFailedError.
19
21
20
22
var requests = futs
21
23
22
24
while true :
23
- if requests.len == 0 :
25
+ var raceFut: Future [T]
26
+
27
+ try :
28
+ raceFut = await one (requests)
29
+ if raceFut.completed:
30
+ return raceFut
31
+ except ValueError :
24
32
raise newException (
25
33
AllFuturesFailedError , " None of the futures completed successfully"
26
34
)
27
35
28
- var raceFut = await one (requests)
29
- if raceFut.completed:
30
- return raceFut
31
-
32
36
let index = requests.find (raceFut)
33
37
requests.del (index)
You can’t perform that action at this time.
0 commit comments