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

Method WithContext

pool/pool.go:138–146  ·  view source on GitHub ↗

WithContext converts the pool to a ContextPool for tasks that should run under the same context, such that they each respect shared cancellation. For example, WithCancelOnError can be configured on the returned pool to signal that all goroutines should be cancelled upon the first error.

(ctx context.Context)

Source from the content-addressed store, hash-verified

136// For example, WithCancelOnError can be configured on the returned pool to
137// signal that all goroutines should be cancelled upon the first error.
138func (p *Pool) WithContext(ctx context.Context) *ContextPool {
139 p.panicIfInitialized()
140 ctx, cancel := context.WithCancel(ctx)
141 return &ContextPool{
142 errorPool: p.WithErrors().deref(),
143 ctx: ctx,
144 cancel: cancel,
145 }
146}
147
148func (p *Pool) worker() {
149 // The only time this matters is if the task panics.

Callers 3

TestContextPoolFunction · 0.45
TestResultContextPoolFunction · 0.45

Calls 3

panicIfInitializedMethod · 0.95
WithErrorsMethod · 0.95
derefMethod · 0.45

Tested by 3

TestContextPoolFunction · 0.36
TestResultContextPoolFunction · 0.36