summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/uasyncio/funcs.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-06-05 21:26:27 +1000
committerDamien George <damien.p.george@gmail.com>2020-06-10 22:29:44 +1000
commita4c96fb3b0c5e3bf83238a0edd0fbcbfd96208c8 (patch)
tree32f02633f7a2aae51e3882693cdcfa8122e73f15 /extmod/uasyncio/funcs.py
parentf3062b5cbdeea5900486a38902e3155117ebf820 (diff)
downloadmicropython-a4c96fb3b0c5e3bf83238a0edd0fbcbfd96208c8.tar.gz
micropython-a4c96fb3b0c5e3bf83238a0edd0fbcbfd96208c8.zip
extmod/uasyncio: Add asyncio.wait_for_ms function.
Fixes issue #6107.
Diffstat (limited to 'extmod/uasyncio/funcs.py')
-rw-r--r--extmod/uasyncio/funcs.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/extmod/uasyncio/funcs.py b/extmod/uasyncio/funcs.py
index 7a4bddf256..6e1305c94f 100644
--- a/extmod/uasyncio/funcs.py
+++ b/extmod/uasyncio/funcs.py
@@ -4,16 +4,16 @@
from . import core
-async def wait_for(aw, timeout):
+async def wait_for(aw, timeout, sleep=core.sleep):
aw = core._promote_to_task(aw)
if timeout is None:
return await aw
- def cancel(aw, timeout):
- await core.sleep(timeout)
+ def cancel(aw, timeout, sleep):
+ await sleep(timeout)
aw.cancel()
- cancel_task = core.create_task(cancel(aw, timeout))
+ cancel_task = core.create_task(cancel(aw, timeout, sleep))
try:
ret = await aw
except core.CancelledError:
@@ -29,6 +29,10 @@ async def wait_for(aw, timeout):
return ret
+def wait_for_ms(aw, timeout):
+ return wait_for(aw, timeout, core.sleep_ms)
+
+
async def gather(*aws, return_exceptions=False):
ts = [core._promote_to_task(aw) for aw in aws]
for i in range(len(ts)):