code: func NewCancelReadCloser(ctx context.Context, in io.ReadCloser) io.ReadCloser {
  	pR, pW := io.Pipe()
  
  	// Create a context used to signal when the pipe is closed
  	doneCtx, cancel := context.WithCancel(context.Background())
  
  	p := &cancelReadCloser{
  		cancel: cancel,
  		pR:     pR,
  		pW:     pW,
  	}
  
  	go func() {
  		_, err := io.Copy(pW, in)
  		select {
  		case <-ctx.Done():
  			// If the context was closed, p.closeWithError
  			// was already called. Calling it again would
  			// change the error that Read returns.
  		default:
  			p.closeWithError(err)
  		}
  		in.Close()
  	}()
  	go func() {
  		for {
  			select {
  			case <-ctx.Done():
  				p.closeWithError(ctx.Err())
  			case <-doneCtx.Done():
  				return
  			}
  		}
  	}()
  
  	return p
  }
docs: // NewCancelReadCloser creates a wrapper that closes the ReadCloser when the
  // context is cancelled. The returned io.ReadCloser must be closed when it is
  // no longer needed.