-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnative_coroutine_send.py
More file actions
40 lines (33 loc) · 899 Bytes
/
native_coroutine_send.py
File metadata and controls
40 lines (33 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Awaitable:
def __await__(self):
value = yield 1
print("Awaitable received:", value)
value = yield 2
print("Awaitable received:", value)
value = yield 3
print("Awaitable received:", value)
return 42
async def foo():
print("foo start")
result = await Awaitable()
print("foo received result:", result)
print("foo end")
async def bar():
print("bar start")
if __name__ == "__main__":
try:
f_coro = foo()
f_coro.send(None)
v = f_coro.send("one")
print("coro return", v)
v = f_coro.send("two")
print("coro return", v)
v = f_coro.send("three")
print("coro return", v)
except Exception as e:
print("f_coro error", e)
try:
b_coro = bar()
b_coro.send(None)
except Exception as e:
print("b_coro error", e)