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.
63 lines
1.2 KiB
63 lines
1.2 KiB
package errgroup
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
func fakeRunTask(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func ExampleGroup_group() {
|
|
g := Group{}
|
|
g.Go(func(context.Context) error {
|
|
return fakeRunTask(context.Background())
|
|
})
|
|
g.Go(func(context.Context) error {
|
|
return fakeRunTask(context.Background())
|
|
})
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|
|
func ExampleGroup_ctx() {
|
|
g := WithContext(context.Background())
|
|
g.Go(func(ctx context.Context) error {
|
|
return fakeRunTask(ctx)
|
|
})
|
|
g.Go(func(ctx context.Context) error {
|
|
return fakeRunTask(ctx)
|
|
})
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|
|
func ExampleGroup_cancel() {
|
|
g := WithCancel(context.Background())
|
|
g.Go(func(ctx context.Context) error {
|
|
return fakeRunTask(ctx)
|
|
})
|
|
g.Go(func(ctx context.Context) error {
|
|
return fakeRunTask(ctx)
|
|
})
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|
|
func ExampleGroup_maxproc() {
|
|
g := Group{}
|
|
// set max concurrency
|
|
g.GOMAXPROCS(2)
|
|
g.Go(func(ctx context.Context) error {
|
|
return fakeRunTask(context.Background())
|
|
})
|
|
g.Go(func(ctx context.Context) error {
|
|
return fakeRunTask(context.Background())
|
|
})
|
|
if err := g.Wait(); err != nil {
|
|
// handle err
|
|
}
|
|
}
|
|
|