From 689931c5b02f7509a125f06480d3673ac85f21d5 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 25 Jun 2012 11:28:24 -0700 Subject: [PATCH] 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 --- doc/go_spec.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 90acc1704e..53089160f1 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -3184,6 +3184,9 @@ the value of the receive operation <-ch is the value received from the channel ch. The type of the value is the element type of the channel. The expression blocks until a value is available. Receiving from a nil channel blocks forever. +Receiving from a closed channel always succeeds, +immediately returning the element type's zero +value.

@@ -3204,11 +3207,11 @@ var x, ok = <-ch
 

-yields an additional result. -The boolean variable ok indicates whether -the received value was sent on the channel (true) -or is a zero value returned -because the channel is closed and empty (false). +yields an additional result of type bool reporting whether the +communication succeeded. The value of ok is true +if the value received was delivered by a successful send operation to the +channel, or false if it is a zero value generated because the +channel is closed and empty.