mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
proper usage of asyncio.wait() for first completed
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user