]> Cypherpunks repositories - gostls13.git/commitdiff
io: add example for Pipe
authorGuilherme Rezende <guilhermebr@gmail.com>
Mon, 24 Jul 2017 16:19:58 +0000 (13:19 -0300)
committerJoe Tsai <thebrokentoaster@gmail.com>
Tue, 22 Aug 2017 19:42:20 +0000 (19:42 +0000)
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>

src/io/example_test.go

index af4785372679ad056791697182cbb689164ae145..edcd0086f5b97f162a2a8e3198494b21142753cb 100644 (file)
@@ -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
+}