mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
refactor: simplify running non-async callback using asyncio.to_thread
This commit is contained in:
parent
7e8dcc6852
commit
47c6141f8c
1 changed files with 1 additions and 5 deletions
|
|
@ -41,11 +41,7 @@ class CallableObject:
|
|||
wrapped = partial(self.callback, *args, **self._prepare_kwargs(kwargs))
|
||||
if self.awaitable:
|
||||
return await wrapped()
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
context = contextvars.copy_context()
|
||||
wrapped = partial(context.run, wrapped)
|
||||
return await loop.run_in_executor(None, wrapped)
|
||||
return await asyncio.to_thread(wrapped)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue