1
0
mirror of https://github.com/golang/go synced 2024-11-22 01:04:40 -07:00

add a little text clarifying the behavior of 'select'

R=gri
DELTA=18  (8 added, 2 deleted, 8 changed)
OCL=16356
CL=16356
This commit is contained in:
Rob Pike 2008-10-02 10:37:12 -07:00
parent d015f896bb
commit cd368a259e

View File

@ -4,7 +4,7 @@ The Go Programming Language Specification (DRAFT)
Robert Griesemer, Rob Pike, Ken Thompson Robert Griesemer, Rob Pike, Ken Thompson
---- ----
(October 1 2008) (October 2 2008)
This document is a semi-formal specification of the Go systems This document is a semi-formal specification of the Go systems
@ -2119,18 +2119,24 @@ cases all referring to communication operations.
SelectStat = "select" "{" { CommClause } "}" . SelectStat = "select" "{" { CommClause } "}" .
CommClause = CommCase [ StatementList [ ";" ] ] . CommClause = CommCase [ StatementList [ ";" ] ] .
CommCase = ( "default" | ( "case" ( SendCase | RecvCase) ) ) ":" . CommCase = ( "default" | ( "case" ( SendExpr | RecvExpr) ) ) ":" .
SendCase = SendExpr .
RecvCase = RecvExpr .
SendExpr = Expression "<-" Expression . SendExpr = Expression "<-" Expression .
RecvExpr = [ PrimaryExpr ( "=" | ":=" ) ] "<-" Expression . RecvExpr = [ PrimaryExpr ( "=" | ":=" ) ] "<-" Expression .
The select statement evaluates all the channel (pointers) involved. First, for all the send and receive expressions in the select
If any of the channels can proceed, the corresponding communication statement, the channel expression is evaluated. If any of the
and statements are evaluated. Otherwise, if there is a default case, resulting channels can proceed, one is chosen and the corresponding
that executes; if not, the statement blocks until one of the communication (including the value to be sent, if any) and statements
communications can complete. A channel pointer may be nil, which is are evaluated. Otherwise, if there is a default case, that executes;
equivalent to that case not being present in the select statement. if not, the statement blocks until one of the communications can
complete. The channels are not re-evaluated. A channel pointer
may be nil, which is equivalent to that case not being present in
the select statement.
Note that since all the channels are evaluated, any side effects in
that evaluation will occur for all the channels in the select. On the
other hand, for sends, only the communication that proceeds has
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