mirror of
https://github.com/golang/go
synced 2024-11-22 04:44:39 -07:00
Revised wording about sends.
Evaluation is done before communication starts. R=gri DELTA=19 (4 added, 1 deleted, 14 changed) OCL=16357 CL=16416
This commit is contained in:
parent
ed139c1e37
commit
569a107e0d
@ -1756,8 +1756,10 @@ a channel and a value (expression):
|
|||||||
ch <- 3
|
ch <- 3
|
||||||
|
|
||||||
In this form, the send operation is an (expression) statement that
|
In this form, the send operation is an (expression) statement that
|
||||||
blocks until the send can proceed, at which point the value is
|
sends the value on the channel. Both the channel and the expression
|
||||||
transmitted on the channel.
|
are evaluated before communication begins. Communication blocks
|
||||||
|
until the send can proceed, at which point the value is transmitted
|
||||||
|
on the channel.
|
||||||
|
|
||||||
If the send operation appears in an expression context, the value
|
If the send operation appears in an expression context, the value
|
||||||
of the expression is a boolean and the operation is non-blocking.
|
of the expression is a boolean and the operation is non-blocking.
|
||||||
@ -1775,6 +1777,7 @@ success of the operation. If the program does not test the value,
|
|||||||
the operation blocks until it succeeds.
|
the operation blocks until it succeeds.
|
||||||
|
|
||||||
TODO: Adjust the above depending on how we rule on the ok semantics.
|
TODO: Adjust the above depending on how we rule on the ok semantics.
|
||||||
|
For instance, does the sent expression get evaluated if ok is false?
|
||||||
|
|
||||||
The receive operation uses the prefix unary operator "<-".
|
The receive operation uses the prefix unary operator "<-".
|
||||||
The value of the expression is the value received:
|
The value of the expression is the value received:
|
||||||
@ -2123,20 +2126,20 @@ cases all referring to communication operations.
|
|||||||
SendExpr = Expression "<-" Expression .
|
SendExpr = Expression "<-" Expression .
|
||||||
RecvExpr = [ PrimaryExpr ( "=" | ":=" ) ] "<-" Expression .
|
RecvExpr = [ PrimaryExpr ( "=" | ":=" ) ] "<-" Expression .
|
||||||
|
|
||||||
First, for all the send and receive expressions in the select
|
For all the send and receive expressions in the select
|
||||||
statement, the channel expression is evaluated. If any of the
|
statement, the channel expression is evaluated. Any values
|
||||||
resulting channels can proceed, one is chosen and the corresponding
|
that appear on the right hand side of send expressions are also
|
||||||
communication (including the value to be sent, if any) and statements
|
evaluated. If any of the resulting channels can proceed, one is
|
||||||
are evaluated. Otherwise, if there is a default case, that executes;
|
chosen and the corresponding communication and statements are
|
||||||
|
evaluated. Otherwise, if there is a default case, that executes;
|
||||||
if not, the statement blocks until one of the communications can
|
if not, the statement blocks until one of the communications can
|
||||||
complete. The channels are not re-evaluated. A channel pointer
|
complete. The channels and send expressions are not re-evaluated.
|
||||||
may be nil, which is equivalent to that case not being present in
|
A channel pointer may be nil, which is equivalent to that case not
|
||||||
the select statement.
|
being present in the select statement.
|
||||||
|
|
||||||
Note that since all the channels are evaluated, any side effects in
|
Since all the channels and send expressions are evaluated, any side
|
||||||
that evaluation will occur for all the channels in the select. On the
|
effects in that evaluation will occur for all the communications
|
||||||
other hand, for sends, only the communication that proceeds has
|
in the select.
|
||||||
its right-hand-side expression evaluated.
|
|
||||||
|
|
||||||
If the channel sends or receives an interface type, its
|
If the channel sends or receives an interface type, its
|
||||||
communication can proceed only if the type of the communication
|
communication can proceed only if the type of the communication
|
||||||
|
Loading…
Reference in New Issue
Block a user