github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/k8s/portforward/error.go (about)

     1  package portforward
     2  
     3  import "sync"
     4  
     5  // A little data structure to get the first error
     6  // from many connections.
     7  type errorHandler struct {
     8  	once  sync.Once
     9  	errCh chan error
    10  }
    11  
    12  func newErrorHandler() *errorHandler {
    13  	return &errorHandler{
    14  		errCh: make(chan error),
    15  	}
    16  }
    17  
    18  func (h *errorHandler) Close() {
    19  	h.once.Do(func() {})
    20  	close(h.errCh)
    21  }
    22  
    23  func (h *errorHandler) Stop(err error) {
    24  	h.once.Do(func() {
    25  		h.errCh <- err
    26  	})
    27  }
    28  
    29  func (h *errorHandler) Done() chan error {
    30  	return h.errCh
    31  }