sync to async

This commit is contained in:
Robert 2024-03-19 00:24:45 +07:00
parent 75eb1196b0
commit f41b8aabd9
No known key found for this signature in database
GPG Key ID: F631C7FD957D5F22
2 changed files with 12 additions and 0 deletions

View File

View File

@ -0,0 +1,12 @@
import asyncio
from functools import wraps
from typing import Callable, Tuple, Dict
def sync_to_async(function: Callable):
@wraps(function)
async def wrapper(*args: Tuple, **kwargs: Dict):
return await asyncio.to_thread(function, *args, **kwargs)
return wrapper