From 97aa90d251f6f2a951d01b7d1033bc7a42bf6f69 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
-A channel provides a mechanism for two concurrently executing functions
-to synchronize execution and communicate by passing a value of a
-specified element type.
+A channel provides a mechanism for
+concurrently executing functions
+to communicate by
+sending and
+receiving
+values of a specified element type.
The value of an uninitialized channel is
-The Channel types
nil
.
-ChannelType = ( "chan" [ "<-" ] | "<-" "chan" ) ElementType .
+ChannelType = ( "chan" | "chan" "<-" | "<-" "chan" ) ElementType .
<-
operator specifies the channel direction,
+The optional <-
operator specifies the channel direction,
send or receive. If no direction is given, the channel is
-bi-directional.
+bidirectional.
A channel may be constrained only to send or only to receive by
conversion or assignment.
make
,
-which takes the channel type and an optional capacity as arguments:
+which takes the channel type and an optional capacity as arguments:
@@ -1326,21 +1329,35 @@ make(chan int, 100)
-The capacity, in number of elements, sets the size of the buffer in the channel. If the
-capacity is greater than zero, the channel is asynchronous: communication operations
-succeed without blocking if the buffer is not full (sends) or not empty (receives),
-and elements are received in the order they are sent.
-If the capacity is zero or absent, the communication succeeds only when both a sender and
-receiver are ready.
+The capacity, in number of elements, sets the size of the buffer in the channel.
+If the capacity is zero or absent, the channel is unbuffered and communication
+succeeds only when both a sender and receiver are ready. Otherwise, the channel is
+buffered and communication operations succeed without blocking if the buffer
+is not full (sends) or not empty (receives).
A nil
channel is never ready for communication.
A channel may be closed with the built-in function
-close
; the
-multi-valued assignment form of the
+close
.
+The multi-valued assignment form of the
receive operator
-tests whether a channel has been closed.
+reports whether a received value was sent before
+the channel was closed.
+
+A single channel may be used in
+send statements,
+receive operations,
+and calls to the built-in functions
+cap
and
+len
+by any number of goroutines without further synchronization.
+Channels act as first-in-first-out queues.
+For example, if one goroutine sends values on a channel
+and a second goroutine receives them, the values are
+received in the order sent.
nil
channel blocks forever.
A receive operation on a closed channel can always proceed
-immediately, yielding the element type's zero value.
+immediately, yielding the element type's zero value
+after any previously sent values have been received.
@@ -4238,22 +4256,8 @@ A send on a closed channel proceeds by causing a run- A send on anil
channel blocks forever. --Channels act as first-in-first-out queues. -For example, if a single goroutine sends on a channel values -that are received by a single goroutine, the values are received in the order sent. -
- --A single channel may be used for send and receive -operations and calls to the built-in functions -
-cap
and -len
-by any number of goroutines without further synchronization. --ch <- 3 +ch <- 3 // send value 3 to channel ch@@ -5383,8 +5387,8 @@ make(T, n, m) slice slice of type T with length n and capacity m make(T) map map of type T make(T, n) map map of type T with initial space for n elements -make(T) channel synchronous channel of type T -make(T, n) channel asynchronous channel of type T, buffer size n +make(T) channel unbuffered channel of type T +make(T, n) channel buffered channel of type T, buffer size n