diff options
| author | Guilherme Rezende <guilhermebr@gmail.com> | 2017-07-24 13:19:58 -0300 |
|---|---|---|
| committer | Joe Tsai <thebrokentoaster@gmail.com> | 2017-08-22 19:42:20 +0000 |
| commit | 5e5a1ed88d2df462aaab68690ef64d35a416966a (patch) | |
| tree | 8988c55340ea081219f0f7a04ad056fc2ef03184 /src/io/example_test.go | |
| parent | 4a1be1e1da52cc406ef605107e184cb5610f6071 (diff) | |
| download | go-5e5a1ed88d2df462aaab68690ef64d35a416966a.tar.xz | |
io: add example for Pipe
Change-Id: I24374accf48d43edf4bf27ea6ba2245ddca558ad
Reviewed-on: https://go-review.googlesource.com/50910
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/io/example_test.go')
| -rw-r--r-- | src/io/example_test.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/io/example_test.go b/src/io/example_test.go index af47853726..edcd0086f5 100644 --- a/src/io/example_test.go +++ b/src/io/example_test.go @@ -243,3 +243,19 @@ func ExampleMultiWriter() { // some io.Reader stream to be read // some io.Reader stream to be read } + +func ExamplePipe() { + r, w := io.Pipe() + + go func() { + fmt.Fprint(w, "some text to be read\n") + w.Close() + }() + + buf := new(bytes.Buffer) + buf.ReadFrom(r) + fmt.Print(buf.String()) + + // Output: + // some text to be read +} |
