mirror of
				https://github.com/golang/go.git
				synced 2025-10-31 16:50:58 +00:00 
			
		
		
		
	spec: remove closed from language, replaced by x, ok = <-c
R=gri, r, r2 CC=golang-dev https://golang.org/cl/4249065
This commit is contained in:
		
							parent
							
								
									d3d672998f
								
							
						
					
					
						commit
						9f2cb86fe2
					
				
					 1 changed files with 15 additions and 28 deletions
				
			
		|  | @ -1,5 +1,5 @@ | ||||||
| <!-- title The Go Programming Language Specification --> | <!-- title The Go Programming Language Specification --> | ||||||
| <!-- subtitle Version of March 7, 2011 --> | <!-- subtitle Version of March 11, 2011 --> | ||||||
| 
 | 
 | ||||||
| <!-- | <!-- | ||||||
| TODO | TODO | ||||||
|  | @ -1235,8 +1235,11 @@ receiver are ready. | ||||||
| </p> | </p> | ||||||
| 
 | 
 | ||||||
| <p> | <p> | ||||||
| A channel may be closed and tested for closure with the built-in functions | A channel may be closed with the built-in function | ||||||
| <a href="#Close_and_closed"><code>close</code> and <code>closed</code></a>. | <a href="#Close"><code>close</code></a>; the | ||||||
|  | multi-valued assignment form of the | ||||||
|  | <a href="#Receive_operator">receive operator</a> | ||||||
|  | tests whether a channel has been closed. | ||||||
| </p> | </p> | ||||||
| 
 | 
 | ||||||
| <h2 id="Properties_of_types_and_values">Properties of types and values</h2> | <h2 id="Properties_of_types_and_values">Properties of types and values</h2> | ||||||
|  | @ -1496,7 +1499,7 @@ Zero value: | ||||||
| 	nil | 	nil | ||||||
| 
 | 
 | ||||||
| Functions: | Functions: | ||||||
| 	append cap close closed complex copy imag len | 	append cap close complex copy imag len | ||||||
| 	make new panic print println real recover | 	make new panic print println real recover | ||||||
| </pre> | </pre> | ||||||
| 
 | 
 | ||||||
|  | @ -3029,9 +3032,6 @@ f(<-ch) | ||||||
| <-strobe  // wait until clock pulse and discard received value | <-strobe  // wait until clock pulse and discard received value | ||||||
| </pre> | </pre> | ||||||
| 
 | 
 | ||||||
| <!-- |  | ||||||
|     TODO(rsc): Add after a release or two without any x,ok := <-c. |  | ||||||
| 
 |  | ||||||
| <p> | <p> | ||||||
| A receive expression used in an assignment or initialization of the form | A receive expression used in an assignment or initialization of the form | ||||||
| </p> | </p> | ||||||
|  | @ -3049,7 +3049,6 @@ the received value was sent on the channel (<code>true</code>) | ||||||
| or is a <a href="#The_zero_value">zero value</a> returned | or is a <a href="#The_zero_value">zero value</a> returned | ||||||
| because the channel is closed and empty (<code>false</code>). | because the channel is closed and empty (<code>false</code>). | ||||||
| </p> | </p> | ||||||
| --> |  | ||||||
| 
 | 
 | ||||||
| <p> | <p> | ||||||
| Receiving from a <code>nil</code> channel causes a | Receiving from a <code>nil</code> channel causes a | ||||||
|  | @ -4009,9 +4008,8 @@ iteration values for each entry will be produced at most once. | ||||||
| 
 | 
 | ||||||
| <li> | <li> | ||||||
| For channels, the iteration values produced are the successive values sent on | For channels, the iteration values produced are the successive values sent on | ||||||
| the channel until the channel is closed; it does not produce the zero value sent | the channel until the channel is closed | ||||||
| before the channel is closed | (§<a href="#Close"><code>close</code>). | ||||||
| (§<a href="#Close_and_closed"><code>close</code> and <code>closed</code></a>). |  | ||||||
| </li> | </li> | ||||||
| </ol> | </ol> | ||||||
| 
 | 
 | ||||||
|  | @ -4086,12 +4084,9 @@ cases all referring to communication operations. | ||||||
| SelectStmt = "select" "{" { CommClause } "}" . | SelectStmt = "select" "{" { CommClause } "}" . | ||||||
| CommClause = CommCase ":" { Statement ";" } . | CommClause = CommCase ":" { Statement ";" } . | ||||||
| CommCase   = "case" ( SendStmt | RecvStmt ) | "default" . | CommCase   = "case" ( SendStmt | RecvStmt ) | "default" . | ||||||
| RecvStmt   = [ Expression ( "=" | ":=" ) ] RecvExpr . | RecvStmt   = [ Expression [ "," Expression ] ( "=" | ":=" ) ] RecvExpr . | ||||||
| RecvExpr   = Expression . | RecvExpr   = Expression . | ||||||
| </pre> | </pre> | ||||||
| <!-- TODO(rsc): |  | ||||||
| RecvStmt =  [ Expression [ "," Expression ] ( "=" | ":=" ) ] RecvExpr . |  | ||||||
| --> |  | ||||||
| 
 | 
 | ||||||
| <p> | <p> | ||||||
| RecvExpr must be a <a href="#Receive_operator">receive operation</a>. | RecvExpr must be a <a href="#Receive_operator">receive operation</a>. | ||||||
|  | @ -4122,27 +4117,24 @@ in the "select" statement. | ||||||
| If multiple cases can proceed, a pseudo-random fair choice is made to decide | If multiple cases can proceed, a pseudo-random fair choice is made to decide | ||||||
| which single communication will execute. | which single communication will execute. | ||||||
| <p> | <p> | ||||||
| <!-- TODO(rsc): s/variable/& or &s/ --> | The receive case may declare one or two new variables using a | ||||||
| The receive case may declare a new variable using a |  | ||||||
| <a href="#Short_variable_declarations">short variable declaration</a>. | <a href="#Short_variable_declarations">short variable declaration</a>. | ||||||
| </p> | </p> | ||||||
| 
 | 
 | ||||||
| <pre> | <pre> | ||||||
| var c, c1, c2 chan int | var c, c1, c2, c3 chan int | ||||||
| var i1, i2 int | var i1, i2 int | ||||||
| select { | select { | ||||||
| case i1 = <-c1: | case i1 = <-c1: | ||||||
| 	print("received ", i1, " from c1\n") | 	print("received ", i1, " from c1\n") | ||||||
| case c2 <- i2: | case c2 <- i2: | ||||||
| 	print("sent ", i2, " to c2\n") | 	print("sent ", i2, " to c2\n") | ||||||
| <!-- TODO(rsc): add , c3 to channel list above too |  | ||||||
| case i3, ok := <-c3: | case i3, ok := <-c3: | ||||||
| 	if ok { | 	if ok { | ||||||
| 		print("received ", i3, " from c3\n") | 		print("received ", i3, " from c3\n") | ||||||
| 	} else { | 	} else { | ||||||
| 		print("c3 is closed\n") | 		print("c3 is closed\n") | ||||||
| 	} | 	} | ||||||
| --> |  | ||||||
| default: | default: | ||||||
| 	print("no communication\n") | 	print("no communication\n") | ||||||
| } | } | ||||||
|  | @ -4401,8 +4393,7 @@ BuiltinCall = identifier "(" [ BuiltinArgs [ "," ] ] ")" . | ||||||
| BuiltinArgs = Type [ "," ExpressionList ] | ExpressionList . | BuiltinArgs = Type [ "," ExpressionList ] | ExpressionList . | ||||||
| </pre> | </pre> | ||||||
| 
 | 
 | ||||||
| <!-- TODO(rsc): s/.and.closed//g --> | <h3 id="Close">Close</h3> | ||||||
| <h3 id="Close_and_closed">Close and closed</h3> |  | ||||||
| 
 | 
 | ||||||
| <p> | <p> | ||||||
| For a channel <code>c</code>, the built-in function <code>close(c)</code> | For a channel <code>c</code>, the built-in function <code>close(c)</code> | ||||||
|  | @ -4412,12 +4403,8 @@ After calling <code>close</code>, and after any previously | ||||||
| sent values have been received, receive operations will return | sent values have been received, receive operations will return | ||||||
| the zero value for the channel's type without blocking. | the zero value for the channel's type without blocking. | ||||||
| 
 | 
 | ||||||
| <!-- TODO(rsc): delete next sentence, replace with |  | ||||||
| The multi-valued <a href="#Receive_operator">receive operation</a> | The multi-valued <a href="#Receive_operator">receive operation</a> | ||||||
| returns a received value along with an indication of whether the channel is closed. | returns a received value along with an indication of whether the channel is closed. | ||||||
| --> |  | ||||||
| After at least one such zero value has been |  | ||||||
| received, <code>closed(c)</code> returns true. |  | ||||||
| </p> | </p> | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Russ Cox
						Russ Cox