]> granicus.if.org Git - python/commitdiff
asyncio doc: add a "Coroutines and protocols" section
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 24 Jan 2014 16:33:20 +0000 (17:33 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 24 Jan 2014 16:33:20 +0000 (17:33 +0100)
Doc/library/asyncio-protocol.rst
Doc/library/asyncio-stream.rst

index 9e02e84bd97ca2665685885105e19ca0cd547f4f..d35c70da9aa7359feb6a74261096eff577050b08 100644 (file)
@@ -403,6 +403,18 @@ buffer size reaches the low-water mark.
    mark is zero.
 
 
+Coroutines and protocols
+------------------------
+
+Coroutines can be scheduled in a protocol method using :func:`async`, but there
+is not guarantee on the execution order. Protocols are not aware of coroutines
+created in protocol methods and so will not wait for them.
+
+To have a reliable execution order, use :ref:`stream objects <streams>` in a
+coroutine with ``yield from``. For example, the :meth:`StreamWriter.drain`
+coroutine can be used to wait until the write buffer is flushed.
+
+
 Server
 ------
 
index 07725168881322c1936b37456c5cc76bb974a44d..f2a9f1268e6d3ff85a6c32fea6acc54c8a2d4e0f 100644 (file)
@@ -1,5 +1,7 @@
 .. currentmodule:: asyncio
 
+.. _streams:
+
 ++++++++++++++++++++++++
 Streams (high-level API)
 ++++++++++++++++++++++++