mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-16 02:50:48 +00:00
change rule
This commit is contained in:
@ -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):
|
||||
|
Reference in New Issue
Block a user