diff options
author | Jonathan Slenders <jonathan@slenders.be> | 2018-05-22 21:12:56 +0200 |
---|---|---|
committer | Jonathan Slenders <jonathan@slenders.be> | 2018-05-22 21:12:56 +0200 |
commit | 4ba621bc177873cfb7205cae4a0e18920869a847 (patch) | |
tree | 70b5d4ee6b37fc8934fcc870691cc13aaf8fe214 | |
parent | 652bfb3f70e38b6e20bf44353a059d4ff00ba774 (diff) |
Improved asyncio documentation.
-rw-r--r-- | docs/pages/advanced_topics/asyncio.rst | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/docs/pages/advanced_topics/asyncio.rst b/docs/pages/advanced_topics/asyncio.rst index d34d125c..c5b202a1 100644 --- a/docs/pages/advanced_topics/asyncio.rst +++ b/docs/pages/advanced_topics/asyncio.rst @@ -9,7 +9,7 @@ line of code, it is possible to run prompt_toolkit on top of asyncio: .. code:: - from prompt_toolkit.eventloop.defaults import use_asyncio_event_loop + from prompt_toolkit.eventloop import use_asyncio_event_loop use_asyncio_event_loop() @@ -23,6 +23,24 @@ an asyncio `Future` for use in an asyncio context, like asyncio's ``run_until_complete``. The cleanest way is to call :meth:`~prompt_toolkit.eventloop.Future.to_asyncio_future`. +So,the typical boilerplace for an asyncio application looks like this: + +.. code:: python + + from prompt_toolkit.eventloop import use_asyncio_event_loop + from prompt_toolkit.application import Application + + # Tell prompt_toolkit to use asyncio for the event loop. + use_asyncio_event_loop() + + # Define application. + application = Application( + ... + ) + + # Run the application, and wait for it to finish. + asyncio.get_event_loop().run_until_complete( + application.run_async().to_asyncio_future()) .. warning:: |