Merge pull request #194 from mmcgrana/explain-nonblocking-send

Explain non-blocking sends
This commit is contained in:
Mark McGranaghan 2018-02-09 17:48:25 -05:00 committed by GitHub
commit 33970ecff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -22,7 +22,10 @@ func main() {
fmt.Println("no message received")
}
// A non-blocking send works similarly.
// A non-blocking send works similarly. Here `msg`
// cannot be sent to the `messages` channel, because
// the channel has no buffer and there is no receiver.
// Therefore the `default` case is selected.
msg := "hi"
select {
case messages <- msg:

View File

@ -1,2 +1,2 @@
119ced4df4f79795b163483b6abfd855e76ef577
M972dltae2
a6e0a8bb87153c7ed0de4996172f7ad5d89c6814
n5ttmOsMrrJ

View File

@ -42,7 +42,7 @@ non-blocking multi-way <code>select</code>s.</p>
</td>
<td class="code leading">
<a href="http://play.golang.org/p/M972dltae2"><img title="Run code" src="play.png" class="run" /></a>
<a href="http://play.golang.org/p/n5ttmOsMrrJ"><img title="Run code" src="play.png" class="run" /></a>
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
</pre></div>
@ -98,7 +98,10 @@ it will immediately take the <code>default</code> case.</p>
<tr>
<td class="docs">
<p>A non-blocking send works similarly.</p>
<p>A non-blocking send works similarly. Here <code>msg</code>
cannot be sent to the <code>messages</code> channel, because
the channel has no buffer and there is no receiver.
Therefore the <code>default</code> case is selected.</p>
</td>
<td class="code leading">