initial commit

This commit is contained in:
callebtc
2022-09-11 04:31:37 +03:00
parent 213968eca7
commit 13a1e47a3d
18 changed files with 1128 additions and 0 deletions

26
core/helpers.py Normal file
View File

@@ -0,0 +1,26 @@
import asyncio
from functools import partial, wraps
def async_wrap(func):
@wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
loop = asyncio.get_event_loop()
partial_func = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, partial_func)
return run
def async_unwrap(to_await):
async_response = []
async def run_and_capture_result():
r = await to_await
async_response.append(r)
loop = asyncio.get_event_loop()
coroutine = run_and_capture_result()
loop.run_until_complete(coroutine)
return async_response[0]