diff options
author | Devaev Maxim <[email protected]> | 2020-03-15 02:42:10 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-03-15 02:42:10 +0300 |
commit | 5b58af4d6f433fcbf16e967404a5cd85a85eefba (patch) | |
tree | 9a40dfc055f59494019eb50fd0e34b232669a665 /kvmd/aiotools.py | |
parent | eb419822cde3c5c482196664a1fd8aed5236f098 (diff) |
proper usage of asyncio.wait() for first completed
Diffstat (limited to 'kvmd/aiotools.py')
-rw-r--r-- | kvmd/aiotools.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/kvmd/aiotools.py b/kvmd/aiotools.py index 18990c2c..10510b77 100644 --- a/kvmd/aiotools.py +++ b/kvmd/aiotools.py @@ -28,8 +28,11 @@ import types import typing +from typing import Tuple from typing import List +from typing import Set from typing import Callable +from typing import Awaitable from typing import Coroutine from typing import Type from typing import TypeVar @@ -86,6 +89,10 @@ async def wait_infinite() -> None: await asyncio.get_event_loop().create_future() +async def wait_first(*aws: Awaitable) -> Tuple[Set[asyncio.Future], Set[asyncio.Future]]: + return (await asyncio.wait(list(aws), return_when=asyncio.FIRST_COMPLETED)) + + # ===== async def afile_write_now(afile: aiofiles.base.AiofilesContextManager, data: bytes) -> None: await afile.write(data) |