diff --git a/asyncio_slow/test_chain.py b/asyncio_slow/test_chain.py new file mode 100644 index 00000000..8d6b9a61 --- /dev/null +++ b/asyncio_slow/test_chain.py @@ -0,0 +1,18 @@ +#https://docs.python.org/3.4/library/asyncio-task.html#example-chain-coroutines +#import asyncio +import asyncio_slow as asyncio + +@asyncio.coroutine +def compute(x, y): + print("Compute %s + %s ..." % (x, y)) + yield from asyncio.sleep(1.0) + return x + y + +@asyncio.coroutine +def print_sum(x, y): + result = yield from compute(x, y) + print("%s + %s = %s" % (x, y, result)) + +loop = asyncio.get_event_loop() +loop.run_until_complete(print_sum(1, 2)) +loop.close()