stream.go 542 B

12345678910111213141516171819202122232425262728293031
  1. package streams
  2. import (
  3. "sync"
  4. streamsv1 "github.com/docker/api/protos/streams/v1"
  5. )
  6. // Stream is a bidirectional stream for container IO
  7. type Stream struct {
  8. streamsv1.Streaming_NewStreamServer
  9. errm sync.Mutex
  10. ErrChan chan<- error
  11. }
  12. // CloseWithError sends the result of an action to the errChan or nil
  13. // if no erros
  14. func (s *Stream) CloseWithError(err error) error {
  15. s.errm.Lock()
  16. defer s.errm.Unlock()
  17. if s.ErrChan != nil {
  18. if err != nil {
  19. s.ErrChan <- err
  20. }
  21. close(s.ErrChan)
  22. s.ErrChan = nil
  23. }
  24. return nil
  25. }