Skip to content

Commit b4d087a

Browse files
committed
move code block to beforfe explanation in coroutine under the hood.
1 parent a8030d6 commit b4d087a

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

Doc/howto/a-conceptual-overview-of-asyncio.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,22 +309,6 @@ paused it.
309309
If the coroutine is being used for the first time (as opposed to being resumed)
310310
``arg`` must be ``None``.
311311

312-
:ref:`yield <yieldexpr>`, like usual, pauses execution and returns control
313-
to the caller.
314-
In the example below, the ``yield``, on line 3, is called by
315-
``... = await rock`` on line 11.
316-
More broadly speaking, ``await`` calls the :meth:`~object.__await__` method of
317-
the given object.
318-
``await`` also does one more very special thing: it propagates (or "passes
319-
along") any ``yield``\ s it receives up the call-chain.
320-
In this case, that's back to ``... = coroutine.send(None)`` on line 16.
321-
322-
The coroutine is resumed via the ``coroutine.send(42)`` call on line 21.
323-
The coroutine picks back up from where it ``yield``\ ed (or paused) on line 3
324-
and executes the remaining statements in its body.
325-
When a coroutine finishes, it raises a :exc:`StopIteration` exception with the
326-
return value attached in the :attr:`~StopIteration.value` attribute.
327-
328312
.. code-block::
329313
:linenos:
330314
@@ -353,6 +337,22 @@ return value attached in the :attr:`~StopIteration.value` attribute.
353337
returned_value = e.value
354338
print(f"Coroutine main() finished and provided value: {returned_value}.")
355339
340+
:ref:`yield <yieldexpr>`, like usual, pauses execution and returns control
341+
to the caller.
342+
In the example above, the ``yield``, on line 3, is called by
343+
``... = await rock`` on line 11.
344+
More broadly speaking, ``await`` calls the :meth:`~object.__await__` method of
345+
the given object.
346+
``await`` also does one more very special thing: it propagates (or "passes
347+
along") any ``yield``\ s it receives up the call-chain.
348+
In this case, that's back to ``... = coroutine.send(None)`` on line 16.
349+
350+
The coroutine is resumed via the ``coroutine.send(42)`` call on line 21.
351+
The coroutine picks back up from where it ``yield``\ ed (or paused) on line 3
352+
and executes the remaining statements in its body.
353+
When a coroutine finishes, it raises a :exc:`StopIteration` exception with the
354+
return value attached in the :attr:`~StopIteration.value` attribute.
355+
356356
That snippet produces this output:
357357

358358
.. code-block:: none

0 commit comments

Comments
 (0)