sync to async
This commit is contained in:
parent
75eb1196b0
commit
f41b8aabd9
0
chain_service/utils/__init__.py
Normal file
0
chain_service/utils/__init__.py
Normal file
12
chain_service/utils/sync_to_async.py
Normal file
12
chain_service/utils/sync_to_async.py
Normal 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
|
||||||
Loading…
Reference in New Issue
Block a user