Skip to content

Commit acdae03

Browse files
committed
asyn.Event: add .wait method.
1 parent 402055e commit acdae03

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

PRIMITIVES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ Synchronous Methods:
205205
* `is_set` No args. Returns `True` if the event is set.
206206
* `value` No args. Returns the value passed to `set`.
207207

208+
Asynchronous Method:
209+
* `wait` For CPython compatibility. Pause until event is set. The CPython
210+
Event is not awaitable.
211+
208212
The optional data value may be used to compensate for the latency in awaiting
209213
the event by passing `loop.time()`.
210214

asyn.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def clear(self):
104104
self._flag = False
105105
self._data = None
106106

107+
async def wait(self): # CPython comptaibility
108+
while not self._flag:
109+
await asyncio.sleep_ms(self.delay_ms)
110+
107111
def __await__(self):
108112
while not self._flag:
109113
await asyncio.sleep_ms(self.delay_ms)

0 commit comments

Comments
 (0)