Coverage for src/lexigram/web/background/decorator.py: 50%
10 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
1from __future__ import annotations
3import asyncio
4from collections.abc import Awaitable, Callable
5from typing import Any
8def background(func: Callable[..., Awaitable[Any]]) -> Callable[..., Awaitable[Any]]:
9 """Decorator to run a function as a background task."""
11 async def wrapper(*args: Any, **kwargs: Any) -> None:
12 if asyncio.iscoroutinefunction(func):
13 await func(*args, **kwargs)
14 else:
15 func(*args, **kwargs)
17 return wrapper