Clarify use of buffered channel in the timeouts example.
The buffered channel prevents goroutine leaks in case the channel doesn't end up being read (as indeed happens to c1). Updates #207
This commit is contained in:
parent
13b0da17de
commit
a34c967eaf
@ -12,7 +12,10 @@ func main() {
|
||||
|
||||
// For our example, suppose we're executing an external
|
||||
// call that returns its result on a channel `c1`
|
||||
// after 2s.
|
||||
// after 2s. Note that the channel is buffered, so the
|
||||
// send in the goroutine is nonblocking. This is a
|
||||
// common pattern to prevent goroutine leaks in case the
|
||||
// channel is never read.
|
||||
c1 := make(chan string, 1)
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
|
@ -1,2 +1,2 @@
|
||||
93343e1aacb14f818c87732914c29ba57afab245
|
||||
MgcfA-xpJO9
|
||||
b1e8d0efbabd0c52271a85fad5ad58dcd1c7c476
|
||||
gyY_qDsRVUe
|
||||
|
7
public/timeouts
generated
7
public/timeouts
generated
@ -44,7 +44,7 @@ elegant thanks to channels and <code>select</code>.</p>
|
||||
|
||||
</td>
|
||||
<td class="code leading">
|
||||
<a href="http://play.golang.org/p/MgcfA-xpJO9"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
||||
<a href="http://play.golang.org/p/gyY_qDsRVUe"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
||||
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
||||
</pre></div>
|
||||
|
||||
@ -80,7 +80,10 @@ elegant thanks to channels and <code>select</code>.</p>
|
||||
<td class="docs">
|
||||
<p>For our example, suppose we’re executing an external
|
||||
call that returns its result on a channel <code>c1</code>
|
||||
after 2s.</p>
|
||||
after 2s. Note that the channel is buffered, so the
|
||||
send in the goroutine is nonblocking. This is a
|
||||
common pattern to prevent goroutine leaks in case the
|
||||
channel is never read.</p>
|
||||
|
||||
</td>
|
||||
<td class="code leading">
|
||||
|
Loading…
x
Reference in New Issue
Block a user