// Package pool tracks worker busy state for one worker type. Workers are // spawn domains reached over channels; the pool owns only the scheduling // state, and the caller owns the channels and the spawned domains. package pool // Pool tracks which worker of a type is currently processing a request. type Pool struct { Busy []bool } // NewPool creates a Pool with capacity n. func NewPool(n int32) (p Pool) { return Pool{Busy: []bool{:n}} } // Len returns the number of workers. func (p *Pool) Len() (n int32) { return len(p.Busy) } // IdleIndex returns the index of the first idle worker, or -1 if all busy. func (p *Pool) IdleIndex() (n int32) { for i, busy := range p.Busy { if !busy { return i } } return -1 }