Files
backend/src/dexorder/util/async_util.py
2025-02-24 20:47:46 -04:00

20 lines
423 B
Python

import asyncio
import inspect
from typing import Union, Awaitable, TypeVar
async def async_yield():
# a value of exactly 0 doesn't seem to work as well, so we use 1 microsecond
await asyncio.sleep(1e-6)
Args = TypeVar('Args')
Return = TypeVar('Return')
Maywaitable = Union[Return, Awaitable[Return]]
async def maywait(obj: Maywaitable):
if inspect.isawaitable(obj):
obj = await obj
return obj