You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: readers.go
    path of file: ./repos/kubeedge/vendor/github.com/docker/docker/pkg/ioutils
    
    the code of the file until where you have to start completion: package ioutils // import "github.com/docker/docker/pkg/ioutils"

import (
	"context"
	"io"

	// make sure crypto.SHA256, crypto.sha512 and crypto.SHA384 are registered
	// TODO remove once https://github.com/opencontainers/go-digest/pull/64 is merged.
	_ "crypto/sha256"
	_ "crypto/sha512"
)

// R
    
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
}