asyncdeffetch(session, url): asyncwith session.get(url) as response: returnawait response.json()
asyncdefmain(product_ids): asyncwith aiohttp.ClientSession() as session: tasks = [] for product_id in product_ids: task = asyncio.create_task(fetch(session, f"{url}/{product_id}")) tasks.append(task) results = await asyncio.gather(*tasks) for result in results: process_data(result)
asyncdefmain_with_sem(product_ids): asyncwith aiohttp.ClientSession() as session: tasks = [] for product_id in product_ids: task = asyncio.create_task(fetch_with_sem(session, f"{url}/{product_id}")) tasks.append(task) results = await asyncio.gather(*tasks) for result in results: process_data(result)