mirror of
https://github.com/rommapp/romm.git
synced 2026-05-04 00:01:30 +08:00
14 lines
449 B
Python
14 lines
449 B
Python
import asyncio
|
|
from collections.abc import Coroutine
|
|
from typing import Any
|
|
|
|
# The event loop only holds weak refs to tasks; hold strong refs until they finish.
|
|
_background_tasks: set[asyncio.Task[Any]] = set()
|
|
|
|
|
|
def fire_and_forget(coro: Coroutine[Any, Any, Any]) -> None:
|
|
"""Schedule a coroutine without awaiting it."""
|
|
task = asyncio.create_task(coro)
|
|
_background_tasks.add(task)
|
|
task.add_done_callback(_background_tasks.discard)
|