aboutsummaryrefslogtreecommitdiff
path: root/tests/basics/async_await2.py
diff options
context:
space:
mode:
authorMark <56205165+gamblor21@users.noreply.github.com>2020-10-16 15:52:45 -0500
committerGitHub <noreply@github.com>2020-10-16 15:52:45 -0500
commit8e6d3e5b91f4c7cdb0dc4743a9a9937708daa624 (patch)
tree6d541d14808bd8456b17303fb654a73300f1adc5 /tests/basics/async_await2.py
parent645382d51d37a40312118eebc11da75639913fce (diff)
parentf0b37313c5adf2ad940d7279aa49620d36d7292d (diff)
Merge branch 'main' into recv_into_size_check6.1.0-alpha.0
Diffstat (limited to 'tests/basics/async_await2.py')
-rw-r--r--tests/basics/async_await2.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/tests/basics/async_await2.py b/tests/basics/async_await2.py
index 7097ce85a..2c5015fb4 100644
--- a/tests/basics/async_await2.py
+++ b/tests/basics/async_await2.py
@@ -1,22 +1,22 @@
# test await expression
-import sys
-if sys.implementation.name in ('micropython', 'circuitpython'):
- # uPy allows normal generators to be awaitables
- coroutine = lambda f: f
-else:
- import types
- coroutine = types.coroutine
+# uPy allows normal generators to be awaitables.
+# CircuitPython does not.
+# In CircuitPython you need to have an __await__ method on an awaitable like in CPython;
+# and like in CPython, generators do not have __await__.
-@coroutine
-def wait(value):
- print('wait value:', value)
- msg = yield 'message from wait(%u)' % value
- print('wait got back:', msg)
- return 10
+class Awaitable:
+ def __init__(self, value):
+ self.value = value
+
+ def __await__(self):
+ print('wait value:', self.value)
+ msg = yield 'message from wait(%u)' % self.value
+ print('wait got back:', msg)
+ return 10
async def f():
- x = await wait(1)**2
+ x = await Awaitable(1)**2
print('x =', x)
coro = f()