Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
micropython/tests/basics/async_await2.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
27 lines (23 sloc)
588 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test await expression | |
import sys | |
if sys.implementation.name == 'micropython': | |
# uPy allows normal generators to be awaitables | |
coroutine = lambda f: f | |
else: | |
import types | |
coroutine = types.coroutine | |
@coroutine | |
def wait(value): | |
print('wait value:', value) | |
msg = yield 'message from wait({})'.format(value) | |
print('wait got back:', msg) | |
return 10 | |
async def f(): | |
x = await wait(1)**2 | |
print('x =', x) | |
coro = f() | |
print('return from send:', coro.send(None)) | |
try: | |
coro.send('message from main') | |
except StopIteration: | |
print('got StopIteration') |