func (p *Pool) Workers() int {
	p.workerMut.Lock()
	defer p.workerMut.Unlock()
	return len(p.workers)
}
Workers returns the numbers of workers created.
package goroutines
import (
	"context"
	"errors"
	"sync"
	"time"
)
var (
	ErrPoolRelease = errors.New("pool released")
	ErrScheduleTimeout = errors.New("schedule timeout")
)
type TaskFunc func()
type Pool struct {
	initN         int
	totalN        int
	scalable      bool
	taskQueueChan chan TaskFunc
	workerChan    chan *worker
	wg            sync.WaitGroup
	stopOnce      sync.Once
	stopChan      chan struct{}
	workerPool sync.Pool
	workers    []*worker
	workerMut  sync.Mutex
	workerCond *sync.Cond
	metric Metric
}
func NewPool(size int, options ...PoolOption) *Pool {
	o := loadPoolOption(options...)
	if size <= 0 {
		panic(errors.New("the total number of workers must be greater than zero"))
	}
	if o.preAllocWorkers == defaultPreAllocWorkers {
		o.preAllocWorkers = size
	}
	if o.preAllocWorkers > size {
		panic(errors.New("the number of pre-allocated workers must be less than or equal to total"))
	}
	p := Pool{
		initN:         o.preAllocWorkers,
		totalN:        size,
		scalable:      o.preAllocWorkers != size,  
		taskQueueChan: make(chan TaskFunc, o.taskQueueLength),
		workerChan:    make(chan *worker),
		stopChan:      make(chan struct{}),
		metric:        newMetric(),
	}
	p.workerPool.New = func() interface{} {
		return newWorker(p.taskQueueChan, &p.workerPool, p.metric)
	}
	p.adjustWorkerSize(p.initN, false)
	p.workerCond = sync.NewCond(&p.workerMut)
	if p.scalable {
		p.startMiner()
		if o.workerAdjustPeriod != defaultAdjustPeriod {
			p.startRecycler(o.workerAdjustPeriod)
		}
	}
	return &p
}
func (p *Pool) Schedule(task TaskFunc) error {
	return p.schedule(context.Background(), task)
}
func (p *Pool) ScheduleWithTimeout(timeout time.Duration, task TaskFunc) error {
	ctx, cancel := context.WithTimeout(context.Background(), timeout)
	defer cancel()
	return p.schedule(ctx, task)
}
func (p *Pool) ScheduleWithContext(ctx context.Context, task TaskFunc) error {
	return p.schedule(ctx, task)
}
func (p *Pool) Release() {
	p.stopOnce.Do(func() {
		close(p.stopChan)
		p.workerCond.Broadcast()
		p.wg.Wait()
		p.adjustWorkerSize(0, true)
	})
}