func NewPool()

in pkg/sync/pool/pool.go [222:259]


func NewPool(params Params) (*Pool, error) {
	if err := params.Validate(); err != nil {
		return nil, err
	}

	// this buffer roughly means that each worker can have 128 items
	// in the queue
	var queueBuffer = params.Size * 128
	// Since there can be in flight items already picked up by the workers
	// the max leftover size should be the buffer + the number of workers.
	var leftoverBuffer = queueBuffer + params.Size

	var pool = Pool{
		size:      params.Size,
		run:       params.Run,
		timeouts:  params.Timeout,
		queue:     make(chan Validator, queueBuffer),
		leftovers: make(chan Validator, leftoverBuffer),
		signals: Signals{
			Stop:        make(chan struct{}),
			Stopped:     make(chan bool),
			Finish:      make(chan struct{}),
			Added:       make(chan struct{}),
			StopMonitor: make(chan struct{}),
		},
		state: &State{
			Errors:     new(Errors),
			monitoring: true,
		},
		errors:   make(chan error),
		writer:   params.Writer,
		failFast: params.FailFast,
	}

	go pool.monitor(nil)

	return &pool, nil
}