Title: make Event an Awaitable
Type: Stage:
Components: asyncio Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, ktbarrett, yselivanov
Priority: normal Keywords:

Created on 2021-06-10 07:34 by ktbarrett, last changed 2021-06-28 18:21 by ktbarrett.

Messages (1)
msg395511 - (view) Author: Kaleb Barrett (ktbarrett) Date: 2021-06-10 07:34
Following on from I don't agree with the original suggestion to deprecate the wait() method on Events, but I do agree that Event should be made Awaitable. Doing so would make code more expressive, but more importantly improve the ability to use Events with generic code that can already handles the other Awaitable types in asyncio.

There were generally neutral takes on providing both __await__ and wait, besides Yury Selivanov who implied it was complex (???). I just tried the below, but maybe I'm missing something?

class AwaitableEvent(Awaitable[None], Event):

    def __await__(self) -> None:
        yield from self.wait().__await__()

    __iter__ = __await__
Date User Action Args
2021-06-28 18:21:33ktbarrettsettitle: make Event and Awaitable -> make Event an Awaitable
2021-06-10 07:34:22ktbarrettcreate