()
| 14 | ) |
| 15 | |
| 16 | func ExampleContextPool_WithCancelOnError() { |
| 17 | p := New(). |
| 18 | WithMaxGoroutines(4). |
| 19 | WithContext(context.Background()). |
| 20 | WithCancelOnError() |
| 21 | for i := 0; i < 3; i++ { |
| 22 | i := i |
| 23 | p.Go(func(ctx context.Context) error { |
| 24 | if i == 2 { |
| 25 | return errors.New("I will cancel all other tasks!") |
| 26 | } |
| 27 | <-ctx.Done() |
| 28 | return nil |
| 29 | }) |
| 30 | } |
| 31 | err := p.Wait() |
| 32 | fmt.Println(err) |
| 33 | // Output: |
| 34 | // I will cancel all other tasks! |
| 35 | } |
| 36 | |
| 37 | func TestContextPool(t *testing.T) { |
| 38 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…