Documentation
¶
Overview ¶
Package waitgroup provides a wrapper around sync.WaitGroup to simplify launching goroutines and waiting for their completion.
Example ¶
package main
import (
"fmt"
"time"
"github.com/goaux/waitgroup"
)
func main() {
var sy waitgroup.Sync
results := make(chan string, 3)
sy.Go(func() {
time.Sleep(100 * time.Millisecond)
results <- "First task done"
})
sy.Go(func() {
time.Sleep(200 * time.Millisecond)
results <- "Second task done"
})
sy.Go(func() {
time.Sleep(50 * time.Millisecond)
results <- "Third task done"
})
// Wait for all goroutines to complete
sy.Wait()
close(results)
// Print results in the order they were added to the channel
for result := range results {
fmt.Println(result)
}
}
Output: Third task done First task done Second task done
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.