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

Method Go

pool/pool.go:39–70  ·  view source on GitHub ↗

Go submits a task to be run in the pool. If all goroutines in the pool are busy, a call to Go() will block until the task can be started.

(f func())

Source from the content-addressed store, hash-verified

37// Go submits a task to be run in the pool. If all goroutines in the pool
38// are busy, a call to Go() will block until the task can be started.
39func (p *Pool) Go(f func()) {
40 p.init()
41
42 if p.limiter == nil {
43 // No limit on the number of goroutines.
44 select {
45 case p.tasks <- f:
46 // A goroutine was available to handle the task.
47 default:
48 // No goroutine was available to handle the task.
49 // Spawn a new one and send it the task.
50 p.handle.Go(p.worker)
51 p.tasks <- f
52 }
53 } else {
54 select {
55 case p.limiter <- struct{}{}:
56 // If we are below our limit, spawn a new worker rather
57 // than waiting for one to become available.
58 p.handle.Go(p.worker)
59
60 // We know there is at least one worker running, so wait
61 // for it to become available. This ensures we never spawn
62 // more workers than the number of tasks.
63 p.tasks <- f
64 case p.tasks <- f:
65 // A worker is available and has accepted the task.
66 return
67 }
68 }
69
70}
71
72// Wait cleans up spawned goroutines, propagating any panics that were
73// raised by a tasks.

Callers 11

ExampleResultPoolFunction · 0.45
TestResultGroupFunction · 0.45
TestContextPoolFunction · 0.45
ExampleErrorPoolFunction · 0.45
TestErrorPoolFunction · 0.45
TestResultErrorGroupFunction · 0.45
TestResultContextPoolFunction · 0.45
ExamplePoolFunction · 0.45
TestPoolFunction · 0.45
BenchmarkPoolFunction · 0.45

Calls 1

initMethod · 0.95

Tested by 11

ExampleResultPoolFunction · 0.36
TestResultGroupFunction · 0.36
TestContextPoolFunction · 0.36
ExampleErrorPoolFunction · 0.36
TestErrorPoolFunction · 0.36
TestResultErrorGroupFunction · 0.36
TestResultContextPoolFunction · 0.36
ExamplePoolFunction · 0.36
TestPoolFunction · 0.36
BenchmarkPoolFunction · 0.36