diff options
Diffstat (limited to 'src/sync/example_test.go')
| -rw-r--r-- | src/sync/example_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/sync/example_test.go b/src/sync/example_test.go index ed240e57ae..a019beebc5 100644 --- a/src/sync/example_test.go +++ b/src/sync/example_test.go @@ -26,6 +26,26 @@ func ExampleWaitGroup() { "http://www.example.com/", } for _, url := range urls { + // Launch a goroutine to fetch the URL. + wg.Go(func() { + // Fetch the URL. + http.Get(url) + }) + } + // Wait for all HTTP fetches to complete. + wg.Wait() +} + +// This example is equivalent to the main example, but uses Add/Done +// instead of Go. +func ExampleWaitGroup_addAndDone() { + var wg sync.WaitGroup + var urls = []string{ + "http://www.golang.org/", + "http://www.google.com/", + "http://www.example.com/", + } + for _, url := range urls { // Increment the WaitGroup counter. wg.Add(1) // Launch a goroutine to fetch the URL. |
