Skip to content

Commit c56b423

Browse files
committed
primitives/Delay_ms: .clear() clears Event.
1 parent 0161289 commit c56b423

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

v3/docs/TUTORIAL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ Synchronous methods:
12121212
6. `callback` args `func=None`, `args=()`. Allows the callable and its args to
12131213
be assigned, reassigned or disabled at run time.
12141214
7. `deinit` No args. Cancels the running task. See [Object scope](./TUTORIAL.md#44-object-scope).
1215+
8. `clear` No args. Clears the `Event` decribed in `wait` below.
12151216

12161217
Asynchronous method:
12171218
1. `wait` One or more tasks may wait on a `Delay_ms` instance. Pause until the
@@ -1251,6 +1252,7 @@ from primitives.delay_ms import Delay_ms
12511252

12521253
async def foo(n, d):
12531254
await d.wait()
1255+
d.clear() # Task waiting on the Event must clear it
12541256
print('Done in foo no.', n)
12551257

12561258
async def my_app():

v3/primitives/delay_ms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, func=None, args=(), duration=1000):
2626
self._trig = asyncio.ThreadSafeFlag()
2727
self._tout = asyncio.Event() # Timeout event
2828
self.wait = self._tout.wait # Allow: await wait_ms.wait()
29+
self.clear = self._tout.clear
2930
self._ttask = self._fake # Timer task
3031
self._mtask = asyncio.create_task(self._run()) #Main task
3132

@@ -40,7 +41,6 @@ async def _run(self):
4041
async def _timer(self, dt):
4142
await asyncio.sleep_ms(dt)
4243
self._tout.set() # Only gets here if not cancelled.
43-
self._tout.clear()
4444
self._busy = False
4545
if self._func is not None:
4646
self._retn = launch(self._func, self._args)

0 commit comments

Comments
 (0)