Currently asyncio.Event use deque to store waiter futures. But now that future can be awaited multiple times, maybe use a single future will be faster?
class Event:
def __init__(self):
self._value = False
self.fut = asyncio.Future()
def is_set(self):
return self._value
def set(self):
if not self._value:
self._value = True
self.fut.set_result(True)
self.fut = asyncio.Future()
def clear(self):
self._value = False
async def wait(self):
if self._value:
return True
try:
await self.fut
return True