Spaces:
Sleeping
Sleeping
File size: 594 Bytes
3c5146b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | """Async utility helpers for ProjectCraft."""
import asyncio
from typing import Any, Callable
async def run_in_executor(fn: Callable, *args) -> Any:
"""Run a synchronous function in a thread pool executor without blocking the event loop."""
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, fn, *args)
async def gather_with_errors(*coros) -> list:
"""
Run coroutines in parallel. Returns list of results.
Failed coroutines return the exception object instead of raising.
"""
return await asyncio.gather(*coros, return_exceptions=True)
|