diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/experiments/test_async.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/python/experiments/test_async.py b/python/experiments/test_async.py index 8a9fca38..2f4970bc 100644 --- a/python/experiments/test_async.py +++ b/python/experiments/test_async.py @@ -15,6 +15,22 @@ async def main(): await pomme() await poire() +async def ping(msg): + if msg > 5: + return + print("ping got:", msg) + await asyncio.sleep(1) + msg += 1 + await pong(msg) + +async def pong(msg): + if msg > 5: + return + print("pong got:", msg) + await asyncio.sleep(1) + msg += 1 + await ping(msg) + if __name__ == "__main__": loop = asyncio.get_event_loop() - loop.run_until_complete(asyncio.gather(pomme(), poire())) + loop.run_until_complete(asyncio.gather(ping(1), pomme(), poire())) |
