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

1from __future__ import annotations 

2 

3import asyncio 

4from collections.abc import Awaitable, Callable 

5from typing import Any 

6 

7 

8def background(func: Callable[..., Awaitable[Any]]) -> Callable[..., Awaitable[Any]]: 

9 """Decorator to run a function as a background task.""" 

10 

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) 

16 

17 return wrapper