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.
kratos/pkg/sync/errgroup/example_test.go

48 lines
738 B

6 years ago
package errgroup
import (
"context"
)
func fakeRunTask(ctx context.Context) error {
return nil
}
func ExampleGroup_group() {
g := Group{}
g.Go(fakeRunTask)
g.Go(fakeRunTask)
6 years ago
if err := g.Wait(); err != nil {
// handle err
}
}
func ExampleGroup_ctx() {
g := WithContext(context.Background())
g.Go(fakeRunTask)
g.Go(fakeRunTask)
6 years ago
if err := g.Wait(); err != nil {
// handle err
}
}
func ExampleGroup_cancel() {
g := WithCancel(context.Background())
g.Go(fakeRunTask)
g.Go(fakeRunTask)
6 years ago
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)
6 years ago
if err := g.Wait(); err != nil {
// handle err
}
}