github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/readability/close-cond-good.go (about)

     1  // +build OMIT
     2  
     3  package sample // OMIT
     4  type Stream struct {
     5  	// some fields
     6  	cc chan struct{} // HL
     7  }
     8  
     9  func (s *Stream) Wait() error {
    10  	<-s.cc
    11  	// some code
    12  }
    13  func (s *Stream) Close() {
    14  	// some code
    15  	close(s.cc)
    16  }
    17  func (s *Stream) IsClosed() bool {
    18  	select {
    19  	case <-s.cc:
    20  		return true
    21  	default:
    22  		return false
    23  	}
    24  }