Commit 427674fa authored by Russ Cox's avatar Russ Cox

io: clarify Pipe docs

Fixes #14139.

Change-Id: I6d2181720c38582b3d2160e94c7593a6cb4fc60f
Reviewed-on: https://go-review.googlesource.com/31321Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 736443c1
...@@ -148,7 +148,7 @@ type PipeWriter struct { ...@@ -148,7 +148,7 @@ type PipeWriter struct {
} }
// Write implements the standard Write interface: // Write implements the standard Write interface:
// it writes data to the pipe, blocking until readers // it writes data to the pipe, blocking until one or more readers
// have consumed all the data or the read end is closed. // have consumed all the data or the read end is closed.
// If the read end is closed with an error, that err is // If the read end is closed with an error, that err is
// returned as err; otherwise err is ErrClosedPipe. // returned as err; otherwise err is ErrClosedPipe.
...@@ -175,11 +175,17 @@ func (w *PipeWriter) CloseWithError(err error) error { ...@@ -175,11 +175,17 @@ func (w *PipeWriter) CloseWithError(err error) error {
// Pipe creates a synchronous in-memory pipe. // Pipe creates a synchronous in-memory pipe.
// It can be used to connect code expecting an io.Reader // It can be used to connect code expecting an io.Reader
// with code expecting an io.Writer. // with code expecting an io.Writer.
// Reads on one end are matched with writes on the other, //
// copying data directly between the two; there is no internal buffering. // Reads and Writes on the pipe are matched one to one
// It is safe to call Read and Write in parallel with each other or with // except when multiple Reads are needed to consume a single Write.
// Close. Close will complete once pending I/O is done. Parallel calls to // That is, each Write to the PipeWriter blocks until it has satisfied
// Read, and parallel calls to Write, are also safe: // one or more Reads from the PipeReader that fully consume
// the written data.
// The data is copied directly from the Write to the corresponding
// Read (or Reads); there is no internal buffering.
//
// It is safe to call Read and Write in parallel with each other or with Close.
// Parallel calls to Read and parallel calls to Write are also safe:
// the individual calls will be gated sequentially. // the individual calls will be gated sequentially.
func Pipe() (*PipeReader, *PipeWriter) { func Pipe() (*PipeReader, *PipeWriter) {
p := new(pipe) p := new(pipe)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment