add asyncs.MaybeAwait() - optionally awaitable coroutines

This commit is contained in:
jesopo 2020-04-05 23:37:54 +01:00
parent 72dc3ebd04
commit 899d4821f0

10
ircrobots/asyncs.py Normal file
View file

@ -0,0 +1,10 @@
from typing import Any, Awaitable, Callable, Generator, Generic, TypeVar
TEvent = TypeVar("TEvent")
class MaybeAwait(Generic[TEvent]):
def __init__(self, func: Callable[[], Awaitable[TEvent]]):
self._func = func
def __await__(self) -> Generator[Any, None, TEvent]:
coro = self._func()
return coro.__await__()