change rule

This commit is contained in:
yanyongyu
2020-08-14 17:41:24 +08:00
parent 04f4d5028e
commit 1dcc43161a
13 changed files with 252 additions and 192 deletions

View File

@ -2,9 +2,23 @@
# -*- coding: utf-8 -*-
import json
import asyncio
import dataclasses
from functools import wraps, partial
from nonebot.typing import overrides
from nonebot.typing import Any, Callable, Awaitable, overrides
def run_sync(func: Callable[..., Any]) -> Callable[..., Awaitable[Any]]:
@wraps(func)
async def _wrapper(*args: Any, **kwargs: Any) -> Any:
loop = asyncio.get_running_loop()
pfunc = partial(func, *args, **kwargs)
result = await loop.run_in_executor(None, pfunc)
return result
return _wrapper
class DataclassEncoder(json.JSONEncoder):