Execute a callable over the objects in the given iterable, in parallel, using no more than ``count`` concurrent calls. Taken from: https://jcalderone.livejournal.com/24285.html
(
iterable: Iterable[_T],
count: int,
callable: Callable[Concatenate[_T, _P], _T2], # noqa: A002
*args: _P.args,
**named: _P.kwargs,
)
| 157 | |
| 158 | |
| 159 | def parallel( |
| 160 | iterable: Iterable[_T], |
| 161 | count: int, |
| 162 | callable: Callable[Concatenate[_T, _P], _T2], # noqa: A002 |
| 163 | *args: _P.args, |
| 164 | **named: _P.kwargs, |
| 165 | ) -> Deferred[list[tuple[bool, Iterator[_T2]]]]: |
| 166 | """Execute a callable over the objects in the given iterable, in parallel, |
| 167 | using no more than ``count`` concurrent calls. |
| 168 | |
| 169 | Taken from: https://jcalderone.livejournal.com/24285.html |
| 170 | """ |
| 171 | coop = Cooperator() |
| 172 | work: Iterator[_T2] = (callable(elem, *args, **named) for elem in iterable) |
| 173 | return DeferredList([coop.coiterate(work) for _ in range(count)]) |
| 174 | |
| 175 | |
| 176 | class _AsyncCooperatorAdapter(Iterator[Deferred[Any]], Generic[_T]): |
no outgoing calls
no test coverage detected