Skip to content

Commit

Permalink
Change example
Browse files Browse the repository at this point in the history
  • Loading branch information
acomagu committed Jun 18, 2019
1 parent 9ef64a6 commit 8cc31fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ Reads block if the internal buffer is empty until the writer is closed.

```Go
r, w := bufpipe.New(nil)
go io.Copy(os.Stdout, r) // The reads block until the writer is closed.

done := make(chan struct{})
go func() {
io.Copy(os.Stdout, r) // The reads block until the writer is closed.
done <- struct{}{}
}()

io.WriteString(w, "abc")
io.WriteString(w, "def")
w.Close()
<-done
// Output: abcdef
```
9 changes: 8 additions & 1 deletion bufpipe_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ import (

func Example() {
r, w := bufpipe.New(nil)
go io.Copy(os.Stdout, r) // => abcdef.

done := make(chan struct{})
go func() {
io.Copy(os.Stdout, r)
done <- struct{}{}
}()

io.WriteString(w, "abc")
io.WriteString(w, "def")
w.Close()
<-done
// Output: abcdef
}

0 comments on commit 8cc31fa

Please sign in to comment.