|
1 | | -from collections.abc import Awaitable |
2 | 1 | from collections.abc import Iterable |
3 | 2 | from concurrent.futures import Future |
4 | 3 | from typing import Any |
5 | 4 | from typing import overload |
6 | 5 |
|
7 | | -from .suspend import suspend |
8 | 6 | from .suspension import Suspension |
9 | 7 |
|
10 | 8 |
|
11 | 9 | class Gather[T](Suspension[T]): |
12 | | - def __init__(self, awaitables: Iterable[Awaitable[Any]]): |
| 10 | + def __init__(self, suspensions: Iterable[Suspension[Any]]): |
13 | 11 | super().__init__() |
14 | | - self.__awaitables = awaitables |
| 12 | + self.__suspensions = suspensions |
15 | 13 |
|
16 | 14 | def submit(self) -> Future[T]: |
17 | 15 | gathered = Future() |
18 | | - futures = [ |
19 | | - suspension.submit() for suspension in map(suspend, self.__awaitables) |
20 | | - ] |
| 16 | + futures = [suspension.submit() for suspension in self.__suspensions] |
21 | 17 |
|
22 | 18 | # concurrent.futures.Future doesn't give us a way to be notified |
23 | 19 | # when a future is running, so we can't reasonably determine when |
@@ -56,26 +52,26 @@ def on_done(future): |
56 | 52 | return gathered |
57 | 53 |
|
58 | 54 |
|
59 | | -A = Awaitable |
| 55 | +S = Suspension |
60 | 56 |
|
61 | 57 |
|
62 | 58 | @overload |
63 | | -def gather[T1](a: A[T1], /) -> Gather[tuple[T1]]: ... |
| 59 | +def gather[T1](s: S[T1], /) -> Gather[tuple[T1]]: ... |
64 | 60 | @overload |
65 | | -def gather[T1, T2](a1: A[T1], a2: A[T2], /) -> Gather[tuple[T1, T2]]: ... |
| 61 | +def gather[T1, T2](s1: S[T1], s2: S[T2], /) -> Gather[tuple[T1, T2]]: ... |
66 | 62 | @overload |
67 | 63 | def gather[T1, T2, T3]( |
68 | | - a1: A[T1], a2: A[T2], a3: A[T3], / |
| 64 | + s1: S[T1], s2: S[T2], s3: S[T3], / |
69 | 65 | ) -> Gather[tuple[T1, T2, T3]]: ... |
70 | 66 | @overload |
71 | 67 | def gather[T1, T2, T3, T4]( |
72 | | - a1: A[T1], a2: A[T2], a3: A[T3], a4: A[T4], / |
| 68 | + s1: S[T1], s2: S[T2], s3: S[T3], s4: S[T4], / |
73 | 69 | ) -> Gather[tuple[T1, T2, T3, T4]]: ... |
74 | 70 | @overload |
75 | 71 | def gather[T1, T2, T3, T4, T5]( |
76 | | - a1: A[T1], a2: A[T2], a3: A[T3], a4: A[T4], a5: A[T5], / |
| 72 | + s1: S[T1], s2: S[T2], s3: S[T3], s4: S[T4], s5: S[T5], / |
77 | 73 | ) -> Gather[tuple[T1, T2, T3, T4, T5]]: ... |
78 | 74 |
|
79 | 75 |
|
80 | | -def gather(*awaitables: Awaitable[Any]) -> Gather[Any]: |
81 | | - return Gather(awaitables) |
| 76 | +def gather(*suspensions: Suspension[Any]) -> Gather[Any]: |
| 77 | + return Gather(suspensions) |
0 commit comments