Skip to content

Commit 427674f

Browse files
committed
io: clarify Pipe docs
Fixes #14139. Change-Id: I6d2181720c38582b3d2160e94c7593a6cb4fc60f Reviewed-on: https://go-review.googlesource.com/31321 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 736443c commit 427674f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/io/pipe.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ type PipeWriter struct {
148148
}
149149

150150
// Write implements the standard Write interface:
151-
// it writes data to the pipe, blocking until readers
151+
// it writes data to the pipe, blocking until one or more readers
152152
// have consumed all the data or the read end is closed.
153153
// If the read end is closed with an error, that err is
154154
// returned as err; otherwise err is ErrClosedPipe.
@@ -175,11 +175,17 @@ func (w *PipeWriter) CloseWithError(err error) error {
175175
// Pipe creates a synchronous in-memory pipe.
176176
// It can be used to connect code expecting an io.Reader
177177
// with code expecting an io.Writer.
178-
// Reads on one end are matched with writes on the other,
179-
// copying data directly between the two; there is no internal buffering.
180-
// It is safe to call Read and Write in parallel with each other or with
181-
// Close. Close will complete once pending I/O is done. Parallel calls to
182-
// Read, and parallel calls to Write, are also safe:
178+
//
179+
// Reads and Writes on the pipe are matched one to one
180+
// except when multiple Reads are needed to consume a single Write.
181+
// That is, each Write to the PipeWriter blocks until it has satisfied
182+
// one or more Reads from the PipeReader that fully consume
183+
// the written data.
184+
// The data is copied directly from the Write to the corresponding
185+
// Read (or Reads); there is no internal buffering.
186+
//
187+
// It is safe to call Read and Write in parallel with each other or with Close.
188+
// Parallel calls to Read and parallel calls to Write are also safe:
183189
// the individual calls will be gated sequentially.
184190
func Pipe() (*PipeReader, *PipeWriter) {
185191
p := new(pipe)

0 commit comments

Comments
 (0)