extmod/uasyncio: Add asyncio.wait_for_ms function.

Fixes issue #6107.
This commit is contained in:
Damien George
2020-06-05 21:26:27 +10:00
parent f3062b5cbd
commit a4c96fb3b0
5 changed files with 59 additions and 4 deletions

View File

@@ -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)):