// NewPoolWithOptions initializes and returns a pool with the given options. You
// can pass in DefaultOptions to use all the default options. Or cal the WithX
// methods of DefaultOptions to change the options you want to change.
546157
func NewPoolWithOptions(options PoolOptions) *Pool {
	pool := &Pool{
		options:         options,
		modelTypeToSpec: map[reflect.Type]*modelSpec{},
		modelNameToSpec: map[string]*modelSpec{},
	}
	pool.redisPool = &redis.Pool{
		MaxIdle:     options.MaxIdle,
		MaxActive:   options.MaxActive,
		IdleTimeout: options.IdleTimeout,
		Wait:        options.Wait,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial(options.Network, options.Address)
			if err != nil {
				return nil, err
			}
			// If a options.Password was provided, use the AUTH command to authenticate
			if options.Password != "" {
				if _, err := c.Do("AUTH", options.Password); err != nil {
					return nil, err
				}
			}
			// Select the database number provided by options.Database
			if _, err := c.Do("Select", options.Database); err != nil {
				_ = c.Close()
				return nil, err
			}
			return c, err
		},
	}
	return pool
}
1354844
func (options PoolOptions) WithNetwork(network string) PoolOptions {
	options.Network = network
	return options
}
437278
func NewOptions() Options {
	return &opts{
		contextPoolOpts:        pool.NewObjectPoolOptions(),
		finalizerPoolOpts:      pool.NewObjectPoolOptions(),
		maxPooledFinalizerCap:  defaultMaxFinalizersCap,
		initPooledFinalizerCap: defaultInitFinalizersCap,
	}
}
1290266
func NewChannelPool(poolConfig *Config) (Pool, error) {
	if poolConfig.InitialCap < 0 || poolConfig.MaxCap <= 0 || poolConfig.InitialCap > poolConfig.MaxCap {
		return nil, errors.New("invalid capacity settings")
	}
	if poolConfig.Factory == nil {
		return nil, errors.New("invalid factory func settings")
	}
	if poolConfig.Close == nil {
		return nil, errors.New("invalid close func settings")
	}

	c := &channelPool{
		conns:       make(chan *idleConn, poolConfig.MaxCap),
		factory:     poolConfig.Factory,
		close:       poolConfig.Close,
		idleTimeout: poolConfig.IdleTimeout,
	}

	if poolConfig.Ping != nil {
		c.ping = poolConfig.Ping
	}

	for i := 0; i < poolConfig.InitialCap; i++ {
		conn, err := c.factory()
		if err != nil {
			c.Release()
			return nil, fmt.Errorf("factory is not able to fill the pool: %s", err)
		}
		c.conns <- &idleConn{conn: conn, t: time.Now()}
	}

	return c, nil
}
176098
func (c *Cmd) WithOptions(options ...string) *Cmd {
	c.options = options
	return c
}
929646
func NewNodeWithOptions(name, kind, ns string, options ...OptionFunc) (*Node, error) {
	compiledNs, err := regexp.Compile(strings.Trim(ns, "/"))
	if err != nil {
		return nil, err
	}
	n := &Node{
		Name:               name,
		Type:               kind,
		path:               name,
		depth:              1,
		nsFilter:           compiledNs,
		pipe:               pipe.NewPipe(nil, name),
		children:           make([]*Node, 0),
		transforms:         make([]*Transform, 0),
		done:               make(chan struct{}),
		c:                  &client.Mock{},
		reader:             &client.MockReader{},
		writer:             &client.MockWriter{},
		resumeTimeout:      60 * time.Second,
		writeTimeout:       defaultWriteTimeout,
		compactionInterval: defaultCompactionInterval,
	}
	// Run the options on it
	for _, option := range options {
		if err := option(n); err != nil {
			return nil, err
		}
	}
	return n, nil
}
344272
func NewOptions(opts []*container.Container, index map[string]*container.Container) Matcher {
	return &options{
		options: opts,
		index:   index,
	}
}
1086697
func New(options *Options) *Pool {
	if options == nil {
		options = &Options{}
	}
	if options.FileMode == 0 {
		options.FileMode = DefaultFileMode
	}
	if options.DirMode == 0 {
		options.DirMode = DefaultDirMode
	}
	if options.ErrorHandler == nil {
		options.ErrorHandler = DefaultErrorHandler
	}
	p := &Pool{
		options:      options,
		errorChannel: make(chan error),
		connections:  map[string]*Connection{},
		mu:           &sync.RWMutex{},
	}
	go func() {
		for {
			p.mu.Lock()
			for _, c := range p.connections {
				c.mu.RLock()
				if !c.closeTime.IsZero() && c.closeTime.Before(time.Now()) {
					p.errorChannel <- c.removeFromPool()
				}
				c.mu.RUnlock()
			}
			p.mu.Unlock()
			time.Sleep(defaultCloseSleep)
		}
	}()
	go func() {
		for err := range p.errorChannel {
			if err != nil {
				p.options.ErrorHandler.HandleError(err)
			}
		}
	}()
	return p
}
591140
func NewPool(numWorkers int, jobQueueLen int) *Pool {
	jobQueue := make(chan Job, jobQueueLen)
	workerPool := make(chan *worker, numWorkers)

	pool := &Pool{
		JobQueue:   jobQueue,
		dispatcher: newDispatcher(workerPool, jobQueue),
	}

	return pool
}
141125
func NewPool(config *PoolConfig) (*Pool, error) {
	finalConfig := getPoolConfig(config)
	hardwareId, err := getHardwareId()
	if err != nil {
		return nil, err
	}
	return &Pool{
		config:  finalConfig,
		id:      hardwareId,
		wg:      &sync.WaitGroup{},
		exit:    make(chan bool),
		workers: make([]*worker, finalConfig.NumWorkers),
		jobs:    make(chan *Job, finalConfig.BatchSize),
	}, nil
}
1328268
func NewPermitPool(permits int) *PermitPool {
	if permits < 1 {
		permits = DefaultParallelOperations
	}
	return &PermitPool{
		sem: make(chan int, permits),
	}
}
521922
func New(size, count int) *Pool {
	return NewEndian(size, count, binary.BigEndian)
}
1024238
func newPool(db *Database) *pool {
	p := &pool{
		database:    db,
		available:   make(map[*resp]*resp),
		inUse:       make(map[*resp]*resp),
		requestChan: make(chan *poolRequest),
	}
	p.backend = loop.Go(p.backendLoop, "redis", db.address, db.index)
	return p
}
1212700
func NewClusterWithOpts(o Opts) (*Cluster, error) {
	if o.PoolSize == 0 {
		o.PoolSize = 10
	}
	if o.PoolThrottle == 0 {
		o.PoolThrottle = 500 * time.Millisecond
	}
	if o.ResetThrottle == 0 {
		o.ResetThrottle = 500 * time.Millisecond
	}

	c := Cluster{
		o:             o,
		mapping:       mapping{},
		pools:         map[string]*pool.Pool{},
		poolThrottles: map[string]<-chan time.Time{},
		callCh:        make(chan func(*Cluster)),
		stopCh:        make(chan struct{}),
	}

	initialPool, err := c.newPool(o.Addr, true)
	if err != nil {
		return nil, err
	}
	c.pools[o.Addr] = initialPool

	go c.spin()
	if err := c.Reset(); err != nil {
		return nil, err
	}
	return &c, nil
}
995491
func NewPool(ctx context.Context, dialOptions ...grpc.DialOption) *Pool {
	return &Pool{
		bgCtx:       ctx,
		dialOptions: dialOptions,
		conns:       make(map[string]*conn),
	}
}
583813
func (c Configuration) NewOptions(iOpts instrument.Options) Options {
	opts := NewOptions().
		SetRetryOptions(c.Retry.NewOptions(iOpts.MetricsScope())).
		SetInstrumentOptions(iOpts)
	if c.KeepAliveEnabled != nil {
		opts = opts.SetTCPConnectionKeepAlive(*c.KeepAliveEnabled)
	}
	if c.KeepAlivePeriod != nil {
		opts = opts.SetTCPConnectionKeepAlivePeriod(*c.KeepAlivePeriod)
	}
	return opts
}
1067257
func WithCreateOptions(opts map[string]string) CreateOption {
	return func(cfg *CreateConfig) {
		cfg.Options = opts
	}
}