add Close() and Closed() to ChanValue

R=r
DELTA=60  (56 added, 3 deleted, 1 changed)
OCL=33868
CL=33872
This commit is contained in:
Russ Cox 2009-08-26 10:47:18 -07:00
parent 06c2c89452
commit 653cef1ba0
5 changed files with 58 additions and 5 deletions

View file

@ -726,6 +726,25 @@ func TestChan(t *testing.T) {
t.Errorf("TrySend 6, recv %d", i);
}
}
// Close
c <- 123;
cv.Close();
if cv.Closed() {
t.Errorf("closed too soon - 1");
}
if i := cv.Recv().(*IntValue).Get(); i != 123 {
t.Errorf("send 123 then close; Recv %d", i);
}
if cv.Closed() {
t.Errorf("closed too soon - 2");
}
if i := cv.Recv().(*IntValue).Get(); i != 0 {
t.Errorf("after close Recv %d", i);
}
if !cv.Closed() {
t.Errorf("not closed");
}
}
// check creation of unbuffered channel