summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Tournoud <damien@platform.sh>2022-12-13 08:22:11 -0800
committerDamien George <damien@micropython.org>2022-12-14 13:25:24 +1100
commit0eba00a92cd422febff560f0f0d1b89f3d0c008f (patch)
treeb98b974943d2e09f7aae5a6e53291ca9a4be05e0
parentb75b5c102c4e4197ff4ed6967070cbf9a5b63b92 (diff)
extmod/uasyncio: Fix syntax of generator functions.
The compiler is not picky right now, but these are actually all syntax errors: - await is only valid in an async function - async functions that use yield are actually async generators (a construct not supported by the compiler right now)
-rw-r--r--extmod/uasyncio/event.py3
-rw-r--r--extmod/uasyncio/funcs.py5
-rw-r--r--extmod/uasyncio/lock.py3
-rw-r--r--extmod/uasyncio/stream.py21
4 files changed, 21 insertions, 11 deletions
diff --git a/extmod/uasyncio/event.py b/extmod/uasyncio/event.py
index 3b5e79d8f..1525bcf3a 100644
--- a/extmod/uasyncio/event.py
+++ b/extmod/uasyncio/event.py
@@ -23,7 +23,8 @@ class Event:
def clear(self):
self.state = False
- async def wait(self):
+ # async
+ def wait(self):
if not self.state:
# Event not set, put the calling task on the event's waiting queue
self.waiting.push(core.cur_task)
diff --git a/extmod/uasyncio/funcs.py b/extmod/uasyncio/funcs.py
index 96883e4fe..23a585aa9 100644
--- a/extmod/uasyncio/funcs.py
+++ b/extmod/uasyncio/funcs.py
@@ -4,7 +4,7 @@
from . import core
-def _run(waiter, aw):
+async def _run(waiter, aw):
try:
result = await aw
status = True
@@ -61,7 +61,8 @@ class _Remove:
pass
-async def gather(*aws, return_exceptions=False):
+# async
+def gather(*aws, return_exceptions=False):
if not aws:
return []
diff --git a/extmod/uasyncio/lock.py b/extmod/uasyncio/lock.py
index f50213d7c..4dae36bc2 100644
--- a/extmod/uasyncio/lock.py
+++ b/extmod/uasyncio/lock.py
@@ -28,7 +28,8 @@ class Lock:
# No Task waiting so unlock
self.state = 0
- async def acquire(self):
+ # async
+ def acquire(self):
if self.state != 0:
# Lock unavailable, put the calling Task on the waiting queue
self.waiting.push(core.cur_task)
diff --git a/extmod/uasyncio/stream.py b/extmod/uasyncio/stream.py
index 785e43555..875353c94 100644
--- a/extmod/uasyncio/stream.py
+++ b/extmod/uasyncio/stream.py
@@ -26,7 +26,8 @@ class Stream:
# TODO yield?
self.s.close()
- async def read(self, n=-1):
+ # async
+ def read(self, n=-1):
r = b""
while True:
yield core._io_queue.queue_read(self.s)
@@ -38,11 +39,13 @@ class Stream:
return r
r += r2
- async def readinto(self, buf):
+ # async
+ def readinto(self, buf):
yield core._io_queue.queue_read(self.s)
return self.s.readinto(buf)
- async def readexactly(self, n):
+ # async
+ def readexactly(self, n):
r = b""
while n:
yield core._io_queue.queue_read(self.s)
@@ -54,7 +57,8 @@ class Stream:
n -= len(r2)
return r
- async def readline(self):
+ # async
+ def readline(self):
l = b""
while True:
yield core._io_queue.queue_read(self.s)
@@ -73,10 +77,11 @@ class Stream:
buf = buf[ret:]
self.out_buf += buf
- async def drain(self):
+ # async
+ def drain(self):
if not self.out_buf:
# Drain must always yield, so a tight loop of write+drain can't block the scheduler.
- return await core.sleep_ms(0)
+ return (yield from core.sleep_ms(0))
mv = memoryview(self.out_buf)
off = 0
while off < len(mv):
@@ -93,7 +98,9 @@ StreamWriter = Stream
# Create a TCP stream connection to a remote host
-async def open_connection(host, port):
+#
+# async
+def open_connection(host, port):
from uerrno import EINPROGRESS
import usocket as socket