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

Function NewReusableGoroutinesPool

concurrency/worker.go:14–21  ·  view source on GitHub ↗

NewReusableGoroutinesPool creates a new worker pool with the given size. Workers are created on demand as they're needed up to the specified size. These workers will run the workloads passed through Go() calls. If all workers are busy, Go() will spawn a new goroutine to run the workload.

(size int)

Source from the content-addressed store, hash-verified

12// These workers will run the workloads passed through Go() calls.
13// If all workers are busy, Go() will spawn a new goroutine to run the workload.
14func NewReusableGoroutinesPool(size int) *ReusableGoroutinesPool {
15 p := &ReusableGoroutinesPool{
16 jobs: make(chan func()),
17 closed: make(chan struct{}),
18 pending: atomic.NewInt64(int64(size)),
19 }
20 return p
21}
22
23type ReusableGoroutinesPool struct {
24 jobs chan func()

Callers 3

benchmarkBatchFunction · 0.92

Calls

no outgoing calls

Tested by 3

benchmarkBatchFunction · 0.74