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