Skip to content

Commit 6bff4db

Browse files
author
Paul Sokolovsky
committed
asyncio_slow: Add example on chaining coros using "yield from" from docs.
1 parent 6ded654 commit 6bff4db

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

asyncio_slow/test_chain.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#https://docs.python.org/3.4/library/asyncio-task.html#example-chain-coroutines
2+
#import asyncio
3+
import asyncio_slow as asyncio
4+
5+
@asyncio.coroutine
6+
def compute(x, y):
7+
print("Compute %s + %s ..." % (x, y))
8+
yield from asyncio.sleep(1.0)
9+
return x + y
10+
11+
@asyncio.coroutine
12+
def print_sum(x, y):
13+
result = yield from compute(x, y)
14+
print("%s + %s = %s" % (x, y, result))
15+
16+
loop = asyncio.get_event_loop()
17+
loop.run_until_complete(print_sum(1, 2))
18+
loop.close()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy