When calling a Channel sink's Write method after having called its Close method, the select behaviour is non-deterministic, and may result in a valid Write call when it should return ErrSinkClosed.
Example:
chSink := NewChannel(10)
ch := chSink.C
queue := NewQueue(chSink)
for i := 0; i < 50; i++ {
queue.Write(i)
}
time.Sleep(time.Millisecond)
// 10 elements in then chan, 1 blocked and 39 in the queue events list
chSink.Close()
outer:
for {
select {
case i := <-ch:
fmt.Println(i)
case <-time.After(time.Second):
break outer // end the infinite loop whenh there is nothing more to print
}
}
Expected output:
It should only print 0-9.
10 is kind of undefined as its Write function was called before the Close but it got stuck there, so either printing or droping it would be ok.
11-49 should not be printed in any way as their Write method is not called until 10's call finishes and Close is being called before that.
When calling a
Channel
sink'sWrite
method after having called itsClose
method, the select behaviour is non-deterministic, and may result in a validWrite
call when it should returnErrSinkClosed
.Example:
Output:
Expected output: It should only print 0-9. 10 is kind of undefined as its
Write
function was called before theClose
but it got stuck there, so either printing or droping it would be ok. 11-49 should not be printed in any way as theirWrite
method is not called until 10's call finishes andClose
is being called before that.