mirror of
https://github.com/golang/go
synced 2024-11-24 05:30:24 -07:00
spec: clarify receive operator
- receiving from a closed channel returns immediately - in the ,ok form, the 2nd result is of type bool, not just boolean (gc and ggcgo agree). Per dsymonds' suggestion. R=r, rsc, ken, iant, dsymonds CC=golang-dev https://golang.org/cl/6333057
This commit is contained in:
parent
277e7e57ca
commit
689931c5b0
@ -1,6 +1,6 @@
|
|||||||
<!--{
|
<!--{
|
||||||
"Title": "The Go Programming Language Specification",
|
"Title": "The Go Programming Language Specification",
|
||||||
"Subtitle": "Version of June 4, 2012",
|
"Subtitle": "Version of June 22, 2012",
|
||||||
"Path": "/ref/spec"
|
"Path": "/ref/spec"
|
||||||
}-->
|
}-->
|
||||||
|
|
||||||
@ -3184,6 +3184,9 @@ the value of the receive operation <code><-ch</code> is the value received
|
|||||||
from the channel <code>ch</code>. The type of the value is the element type of
|
from the channel <code>ch</code>. The type of the value is the element type of
|
||||||
the channel. The expression blocks until a value is available.
|
the channel. The expression blocks until a value is available.
|
||||||
Receiving from a <code>nil</code> channel blocks forever.
|
Receiving from a <code>nil</code> channel blocks forever.
|
||||||
|
Receiving from a <a href="#Close">closed</a> channel always succeeds,
|
||||||
|
immediately returning the element type's <a href="#The_zero_value">zero
|
||||||
|
value</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
@ -3204,11 +3207,11 @@ var x, ok = <-ch
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
yields an additional result.
|
yields an additional result of type <code>bool</code> reporting whether the
|
||||||
The boolean variable <code>ok</code> indicates whether
|
communication succeeded. The value of <code>ok</code> is <code>true</code>
|
||||||
the received value was sent on the channel (<code>true</code>)
|
if the value received was delivered by a successful send operation to the
|
||||||
or is a <a href="#The_zero_value">zero value</a> returned
|
channel, or <code>false</code> if it is a zero value generated because the
|
||||||
because the channel is closed and empty (<code>false</code>).
|
channel is closed and empty.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
Loading…
Reference in New Issue
Block a user