|
@@ -1,5 +1,6 @@
|
|
|
import asyncio
|
|
|
import functools
|
|
|
+from contextlib import nullcontext
|
|
|
from typing import Any, Awaitable, Callable, Optional, Union
|
|
|
|
|
|
from . import globals
|
|
@@ -17,15 +18,15 @@ def safe_invoke(func: Union[Callable, Awaitable], client: Optional[Client] = Non
|
|
|
try:
|
|
|
if isinstance(func, Awaitable):
|
|
|
async def func_with_client():
|
|
|
- with client:
|
|
|
+ with client or nullcontext():
|
|
|
await func
|
|
|
create_task(func_with_client())
|
|
|
else:
|
|
|
- with client:
|
|
|
+ with client or nullcontext():
|
|
|
result = func()
|
|
|
if isinstance(result, Awaitable):
|
|
|
async def result_with_client():
|
|
|
- with client:
|
|
|
+ with client or nullcontext():
|
|
|
await result
|
|
|
create_task(result_with_client())
|
|
|
except:
|