1 // Package pool tracks worker busy state for one worker type. Workers are
2 // spawn domains reached over channels; the pool owns only the scheduling
3 // state, and the caller owns the channels and the spawned domains.
4 package pool
5 6 // Pool tracks which worker of a type is currently processing a request.
7 type Pool struct {
8 Busy []bool
9 }
10 11 // NewPool creates a Pool with capacity n.
12 func NewPool(n int32) (p Pool) {
13 return Pool{Busy: []bool{:n}}
14 }
15 16 // Len returns the number of workers.
17 func (p *Pool) Len() (n int32) { return len(p.Busy) }
18 19 // IdleIndex returns the index of the first idle worker, or -1 if all busy.
20 func (p *Pool) IdleIndex() (n int32) {
21 for i, busy := range p.Busy {
22 if !busy {
23 return i
24 }
25 }
26 return -1
27 }
28