Coverage for async-durable-execution/src/async_durable_execution/task.py: 100%
12 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 16:54 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 16:54 +0000
1from __future__ import annotations
3import asyncio
4from collections.abc import Callable, Coroutine
5from typing import Any, TypeVar
8T = TypeVar("T")
11def create_eager_task(
12 coro_factory: Callable[[], Coroutine[Any, Any, T]],
13) -> asyncio.Task[T]:
14 """Create an operation task, using eager start when the runtime supports it."""
15 loop = asyncio.get_running_loop()
16 coro = coro_factory()
18 eager_task_factory = getattr(asyncio, "eager_task_factory", None)
19 if eager_task_factory is not None:
20 return eager_task_factory(loop, coro)
22 return loop.create_task(coro)