INNER CODE UNIT · Python

worker

ImFeH2/huddol · core/src/fora/adapters/websocket/server.py:242

async def worker[T](operation: Callable[..., T], *args: Any) -> T:
    task = asyncio.create_task(asyncio.to_thread(operation, *args))
    try:
        return await asyncio.shield(task)
    except asyncio.CancelledError:
        await task
        raise


@asynccontextmanager
async def resource[T](
    operation: Callable[..., T],
    release: Callable[[T], None],
    *args: Any,
) -> AsyncIterator[T]:
    task = asyncio.create_task(asyncio.to_thread(operation, *args))
    try:
        result = await asyncio.shield(task)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…