MCPcopy
hub / github.com/grafana/dskit / Go

Method Go

concurrency/worker.go:31–44  ·  view source on GitHub ↗

Go will run the given function in a worker of the pool. If all workers are busy, Go() will spawn a new goroutine to run the workload.

(f func())

Source from the content-addressed store, hash-verified

29// Go will run the given function in a worker of the pool.
30// If all workers are busy, Go() will spawn a new goroutine to run the workload.
31func (p *ReusableGoroutinesPool) Go(f func()) {
32 select {
33 case p.jobs <- f:
34 default:
35 if pending := p.pending.Dec(); pending >= 0 {
36 p.newWorker(f)
37 return
38 } else if pending < math.MinInt64/2 {
39 // Wow, that's a lot of goroutines created, make sure we don't overflow.
40 p.pending.Store(0)
41 }
42 go f()
43 }
44}
45
46func (p *ReusableGoroutinesPool) newWorker(f func()) {
47 go func() {

Callers 6

doWithBatchFunction · 0.80
DoBatchWithOptionsFunction · 0.80
testConcurrencyFunction · 0.80
ForEachJobFunction · 0.80

Calls 1

newWorkerMethod · 0.95

Tested by 3

testConcurrencyFunction · 0.64