You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
738 B
47 lines
738 B
package errgroup
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
func fakeRunTask(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func ExampleGroup_group() {
|
|
g := Group{}
|
|
g.Go(fakeRunTask)
|
|
g.Go(fakeRunTask)
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|
|
func ExampleGroup_ctx() {
|
|
g := WithContext(context.Background())
|
|
g.Go(fakeRunTask)
|
|
g.Go(fakeRunTask)
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|
|
func ExampleGroup_cancel() {
|
|
g := WithCancel(context.Background())
|
|
g.Go(fakeRunTask)
|
|
g.Go(fakeRunTask)
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|
|
func ExampleGroup_maxproc() {
|
|
g := Group{}
|
|
// set max concurrency
|
|
g.GOMAXPROCS(2)
|
|
g.Go(fakeRunTask)
|
|
g.Go(fakeRunTask)
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|