// NewPooledObjectFactory return a DefaultPooledObjectFactory, init with gaven func.
428848
func NewPooledObjectFactory(
	create func(context.Context) (interface{}, error),
	destroy func(ctx context.Context, object *PooledObject) error,
	validate func(ctx context.Context, object *PooledObject) bool,
	activate func(ctx context.Context, object *PooledObject) error,
	passivate func(ctx context.Context, object *PooledObject) error) PooledObjectFactory {
	if create == nil {
		panic(errors.New("make function can not be nil"))
	}
	return &DefaultPooledObjectFactory{
		make: func(ctx context.Context) (*PooledObject, error) {
			o, err := create(ctx)
			if err != nil {
				return nil, err
			}
			return NewPooledObject(o), nil
		},
		destroy:   destroy,
		validate:  validate,
		activate:  activate,
		passivate: passivate}
}
1216296
func newDecodePool(f DecoderFunc) *decoderPool {
	// get a new decoder and type assert to see if it can be reset
	d := f(nil)
	rd, ok := d.(ResettableDecoder)

	p := &decoderPool{fn: f}

	// if the decoder can be reset, create a pool and put the typed decoder in
	if ok {
		p.pool = &sync.Pool{
			New: func() interface{} { return f(nil) },
		}
		p.pool.Put(rd)
	}

	return p
}
1206801
func NewPool(context interface{}, name string, config *PoolConfig) (*WorkPool, error) {
	if config.MinWorkers <= 0 {
		return nil, ErrInvalidMinWorkers
	}

	if config.MaxWorkers <= 0 || config.MaxWorkers < config.MinWorkers {
		return nil, ErrInvalidMaxWorkers
	}

	pool := WorkPool{
		PoolConfig: config,
		name:       name,

		shutdown: make(chan struct{}),
		kill:     make(chan struct{}),
		commands: make(chan int),

		tasks: make(chan doWork),
	}

	pool.manage()

	pool.Add(context, int(pool.MinWorkers))

	//  pool.Add()
	return &pool, nil
}
1190180
func NewPool(network, addr string, size int) (*Pool, error) {
	return NewCustomPool(network, addr, size, redis.Dial)
}
392313
func NewIdentityProviderFactory(context servicecontext.ServiceContext) service.IdentityProviderFactory {
	factory := &identityProviderFactoryImpl{
		BaseService: base.NewBaseService(context),
	}
	return factory
}
1028134
func NewPooledWorkerPoolOptions() PooledWorkerPoolOptions {
	return &pooledWorkerPoolOptions{
		growOnDemand:          defaultGrowOnDemand,
		numShards:             defaultNumShards,
		killWorkerProbability: defaultKillWorkerProbability,
		nowFn: defaultNowFn,
		iOpts: instrument.NewOptions(),
	}
}
857307
func NewObjectStorage(dir *dotgit.DotGit, objectCache cache.Object) *ObjectStorage {
	return NewObjectStorageWithOptions(dir, objectCache, Options{})
}
1235260
func NewCheckedObjectPool(opts ObjectPoolOptions) CheckedObjectPool {
	if opts == nil {
		opts = NewObjectPoolOptions()
	}
	return &checkedObjectPool{
		pool: NewObjectPool(opts),
		finalizerPool: NewObjectPool(opts.SetInstrumentOptions(opts.InstrumentOptions().
			SetMetricsScope(opts.InstrumentOptions().
				MetricsScope().
				SubScope("finalizer-pool")))),
	}
}
520259
func NewObjectCache(dp datapath.Datapath, nodeCfg *datapath.LocalNodeConfiguration) *objectCache {
	return newObjectCache(dp, nodeCfg, option.Config.StateDir)
}
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
}
1213010
func NewPool(New func() Buffer) Pool {
	return &pool{
		pool: sync.Pool{
			New: func() interface{} {
				return New()
			},
		},
	}
}
126786
func NewObject(in interface{}, context *compiler.Context) (*Object, error) {
	errors := make([]error, 0)
	x := &Object{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedAny additional_properties = 1;
		// MAP: Any
		x.AdditionalProperties = make([]*NamedAny, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedAny{}
				pair.Name = k
				result := &Any{}
				handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
				if handled {
					if err != nil {
						errors = append(errors, err)
					} else {
						bytes, _ := yaml.Marshal(v)
						result.Yaml = string(bytes)
						result.Value = resultFromExt
						pair.Value = result
					}
				} else {
					pair.Value, err = NewAny(v, compiler.NewContext(k, context))
					if err != nil {
						errors = append(errors, err)
					}
				}
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
263780
func NewIDPool(minID ID, maxID ID) *IDPool {
	p := &IDPool{
		minID: minID,
		maxID: maxID,
	}

	p.idCache = newIDCache(p.minID, p.maxID)

	return p
}
336299
func NewDefaultPoolConfig() *ObjectPoolConfig {
	return &ObjectPoolConfig{
		LIFO:                     DefaultLIFO,
		MaxTotal:                 DefaultMaxTotal,
		MaxIdle:                  DefaultMaxIdle,
		MinIdle:                  DefaultMinIdle,
		MinEvictableIdleTime:     DefaultMinEvictableIdleTime,
		SoftMinEvictableIdleTime: DefaultSoftMinEvictableIdleTime,
		NumTestsPerEvictionRun:   DefaultNumTestsPerEvictionRun,
		EvictionPolicyName:       DefaultEvictionPolicyName,
		EvitionContext:           context.Background(),
		TestOnCreate:             DefaultTestOnCreate,
		TestOnBorrow:             DefaultTestOnBorrow,
		TestOnReturn:             DefaultTestOnReturn,
		TestWhileIdle:            DefaultTestWhileIdle,
		TimeBetweenEvictionRuns:  DefaultTimeBetweenEvictionRuns,
		BlockWhenExhausted:       DefaultBlockWhenExhausted}
}
1372864
func NewWorkerPool(ctx interface{}, concurrency uint, namespace string, pool *redis.Pool) *WorkerPool {
	return NewWorkerPoolWithOptions(ctx, concurrency, namespace, pool, WorkerPoolOptions{})
}
601990
func NewFactory(config ...FactoryConfig) *Factory {
	conf := defaultFactoryConfig()
	if len(config) == 1 {
		conf = config[0]
	}

	return &Factory{
		registry: make(map[string]registryEntry, conf.RegistryCapacity),
	}
}
818521
func NewFactory(buckets int) metrics.Factory {
	return adapters.WrapFactoryWithoutTags(
		&factory{
			factory: expvar.NewFactory(buckets),
		},
		adapters.Options{},
	)
}