Concurrency Utilities and Patterns¶
-
async for ... in
usim.
first
(*activities: Coroutine[Any, Any, RT], count: Optional[int] = 1) → AsyncIterator[RT][source]¶ Run all
activities
concurrently to get the firstcount
results available- Parameters
activities – activities to run concurrently
count – maximum number of results
- Returns
async iterable of results
- Raises
usim.Concurrent – if any of the
activities
raise an exceptionValueError – if
count
is bigger than number ofactivities
If there are more results than
count
, any remainingactivities
are aborted after yielding the last result. If there are less results thancount
, the iterator finishes after yielding the last result. Ifcount
isNone
, the iterator provides all results.Results are always yielded in the order of becoming available. The initial order of
activities
is irrelevant.
-
await
usim.
collect
(*activities: Coroutine[Any, Any, RT]) → List[RT][source]¶ Run all
activities
concurrently to provide all results- Parameters
activities – activities to run concurrently
- Returns
list of results
- Raises
usim.Concurrent – if any of the
activities
raise an exception
Results are always yielded in the order of the
activities
producing them; the order at which individualactivities
finish is irrelevant. However, results are only available after allactivities
are finished.