MCPcopy Index your code
hub / github.com/sourcegraph/conc / ExampleContextPool_WithCancelOnError

Function ExampleContextPool_WithCancelOnError

pool/context_pool_test.go:16–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func 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
37func TestContextPool(t *testing.T) {
38 t.Parallel()

Callers

nothing calls this directly

Calls 6

NewFunction · 0.70
WithCancelOnErrorMethod · 0.45
WithContextMethod · 0.45
WithMaxGoroutinesMethod · 0.45
GoMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…