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)
| 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. |
| 14 | func 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 | |
| 23 | type ReusableGoroutinesPool struct { |
| 24 | jobs chan func() |
no outgoing calls