Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/async_examples/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


async def fake_api_call(delay, data):
await asyncio.sleep(delay)
return f"Processed: {data}"


Expand All @@ -16,10 +15,9 @@ async def cpu_bound_task(n):


async def some_api_call(urls):
results = []
for url in urls:
res = await fake_api_call(1, url)
results.append(res)
# Launch all calls together; much faster
tasks = [fake_api_call(1, url) for url in urls]
results = await asyncio.gather(*tasks)
return results


Expand Down
Loading