add asyncs.MaybeAwait() - optionally awaitable coroutines
This commit is contained in:
parent
72dc3ebd04
commit
899d4821f0
1 changed files with 10 additions and 0 deletions
10
ircrobots/asyncs.py
Normal file
10
ircrobots/asyncs.py
Normal 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__()
|
Loading…
Add table
Reference in a new issue