Skip to content

Commit 6f5789c

Browse files
committed
Coroutine
1 parent 130971c commit 6f5789c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,14 +2145,14 @@ ValueError: malformed node or string
21452145

21462146
Coroutine
21472147
---------
2148-
* **Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().**
2148+
* **Any function that contains a `'(yield)'` expression returns a coroutine.**
2149+
* **Coroutines are similar to iterators, but data needs to be pulled out of an iterator by calling `'next(<iter>)'`, while we push data into the coroutine by calling `'<coroutine>.send(<el>)'`.**
21492150
* **Coroutines provide more powerful data routing possibilities than iterators.**
2150-
* **If you build a collection of simple data processing components, you can glue them together into complex arrangements of pipes, branches, merging, etc.**
21512151

21522152
### Helper Decorator
2153-
* **All coroutines must be "primed" by first calling next().**
2153+
* **All coroutines must first be "primed" by calling `'next(<coroutine>)'`.**
21542154
* **Remembering to call next() is easy to forget.**
2155-
* **Solved by wrapping coroutines with a decorator:**
2155+
* **Solved by wrapping functions that return a coroutine with a decorator:**
21562156

21572157
```python
21582158
def coroutine(func):

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,13 +1858,13 @@
18581858
</code></pre></div>
18591859

18601860
<div><h2 id="coroutine"><a href="#coroutine" name="coroutine">#</a>Coroutine</h2><ul>
1861-
<li><strong>Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().</strong></li>
1861+
<li><strong>Any function that contains a <code class="python hljs"><span class="hljs-string">'(yield)'</span></code> expression returns a coroutine.</strong></li>
1862+
<li><strong>Coroutines are similar to iterators, but data needs to be pulled out of an iterator by calling <code class="python hljs"><span class="hljs-string">'next(&lt;iter&gt;)'</span></code>, while we push data into the coroutine by calling <code class="python hljs"><span class="hljs-string">'&lt;coroutine&gt;.send(&lt;el&gt;)'</span></code>.</strong></li>
18621863
<li><strong>Coroutines provide more powerful data routing possibilities than iterators.</strong></li>
1863-
<li><strong>If you build a collection of simple data processing components, you can glue them together into complex arrangements of pipes, branches, merging, etc.</strong></li>
18641864
</ul><div><h3 id="helperdecorator">Helper Decorator</h3><ul>
1865-
<li><strong>All coroutines must be "primed" by first calling next().</strong></li>
1865+
<li><strong>All coroutines must first be "primed" by calling <code class="python hljs"><span class="hljs-string">'next(&lt;coroutine&gt;)'</span></code>.</strong></li>
18661866
<li><strong>Remembering to call next() is easy to forget.</strong></li>
1867-
<li><strong>Solved by wrapping coroutines with a decorator:</strong></li>
1867+
<li><strong>Solved by wrapping functions that return a coroutine with a decorator:</strong></li>
18681868
</ul><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">coroutine</span><span class="hljs-params">(func)</span>:</span>
18691869
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">out</span><span class="hljs-params">(*args, **kwargs)</span>:</span>
18701870
cr = func(*args, **kwargs)

0 commit comments

Comments
 (0)