diff --git a/src/asynchrony/various.py b/src/asynchrony/various.py index 95f9f7f..c6016cf 100644 --- a/src/asynchrony/various.py +++ b/src/asynchrony/various.py @@ -1,4 +1,5 @@ import time +import asyncio async def retry_with_backoff(func, max_retries=3): @@ -13,3 +14,13 @@ async def retry_with_backoff(func, max_retries=3): if attempt < max_retries - 1: time.sleep(0.0001 * attempt) raise last_exception + + +async def fetch_user(user_id: int) -> dict: + """Simulates fetching a user from a database""" + await asyncio.sleep(0.0001) + return {"id": user_id, "name": f"User{user_id}"} + + +async def fetch_all_users(user_ids: list[int]) -> list[dict]: + return await asyncio.gather(*[fetch_user(user_id) for user_id in user_ids])