summaryrefslogtreecommitdiff
path: root/ATRI/syncer.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-02-06 00:32:26 +0800
committerKyomotoi <[email protected]>2021-02-06 00:32:26 +0800
commitf5ceb8927f2e7f2a9e29d62c8e4cef876f917249 (patch)
tree40b9dcd6b7d3db486054e3aa9b5a04d25fa2284e /ATRI/syncer.py
parenteb52fab79ada7efe6191e3a5f90179766feaded0 (diff)
downloadATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.tar.gz
ATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.tar.bz2
ATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.zip
🏗 💩 更改项目结构,修复啥b BUG
Diffstat (limited to 'ATRI/syncer.py')
-rw-r--r--ATRI/syncer.py47
1 files changed, 0 insertions, 47 deletions
diff --git a/ATRI/syncer.py b/ATRI/syncer.py
deleted file mode 100644
index b4c59b1..0000000
--- a/ATRI/syncer.py
+++ /dev/null
@@ -1,47 +0,0 @@
-import sys
-import asyncio
-import inspect
-import types
-from functools import singledispatch, wraps
-
-from typing import Any, Callable, Generator
-
-
-PY37 = sys.version_info >= (3, 7)
-
-
-def _is_awaitable(co: Generator[Any, None, Any]) -> bool:
- if PY37:
- return inspect.isawaitable(co)
- else:
- return (isinstance(co, types.GeneratorType) or
- isinstance(co, asyncio.Future))
-
-
-@singledispatch
-def sync(co: Any) -> Any:
- raise TypeError(f'Called with unsupported argument: {co}')
-
-
[email protected](asyncio.Future)
[email protected](types.GeneratorType)
-def sync_co(co: Generator[Any, None, Any]) -> Any:
- if not _is_awaitable(co):
- raise TypeError(f'Called with unsupported argument: {co}')
- return asyncio.get_event_loop().run_until_complete(co)
-
-
[email protected](types.FunctionType)
[email protected](types.MethodType) # type: ignore
-def sync_fu(f: Callable[..., Any]) -> Callable[..., Any]:
- if not asyncio.iscoroutinefunction(f):
- raise TypeError(f'Called with unsupported argument: {f}')
-
- @wraps(f)
- def run(*args, **kwargs) -> Any:
- return asyncio.get_event_loop().run_until_complete(f(*args, **kwargs))
- return run
-
-
-if PY37:
- sync.register(types.CoroutineType)(sync_co)