gather tasks with the specific number concurrency Args: n_task: the number of tasks tasks: task objects
(n_task: int, tasks: List[Task])
| 18 | |
| 19 | |
| 20 | async def gather_with_concurrency(n_task: int, tasks: List[Task]) -> Any: |
| 21 | """ |
| 22 | gather tasks with the specific number concurrency |
| 23 | Args: |
| 24 | n_task: the number of tasks |
| 25 | tasks: task objects |
| 26 | """ |
| 27 | semaphore = asyncio.Semaphore(n_task) |
| 28 | |
| 29 | async def sem_task(task: Task) -> Any: |
| 30 | async with semaphore: |
| 31 | return await task |
| 32 | return await asyncio.gather(*(sem_task(task) for task in tasks)) |
| 33 | |
| 34 | |
| 35 | class SingleIdContainer: |