1# test await expression
2
3try:
4    import usys as sys
5except ImportError:
6    import sys
7if sys.implementation.name == 'micropython':
8    # uPy allows normal generators to be awaitables
9    coroutine = lambda f: f
10else:
11    import types
12    coroutine = types.coroutine
13
14@coroutine
15def wait(value):
16    print('wait value:', value)
17    msg = yield 'message from wait({})'.format(value)
18    print('wait got back:', msg)
19    return 10
20
21async def f():
22    x = await wait(1)**2
23    print('x =', x)
24
25coro = f()
26print('return from send:', coro.send(None))
27try:
28    coro.send('message from main')
29except StopIteration:
30    print('got StopIteration')
31