MCPcopy
hub / github.com/wechaty/python-wechaty / gather_with_concurrency

Function gather_with_concurrency

src/wechaty/utils/async_helper.py:20–32  ·  view source on GitHub ↗

gather tasks with the specific number concurrency Args: n_task: the number of tasks tasks: task objects

(n_task: int, tasks: List[Task])

Source from the content-addressed store, hash-verified

18
19
20async 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
35class SingleIdContainer:

Callers 3

find_allMethod · 0.90
find_allMethod · 0.90

Calls 1

sem_taskFunction · 0.85

Tested by 1