github.com/kaydxh/golang@v0.0.131/pkg/pool/instance/pool.instance.option.go (about) 1 /* 2 *Copyright (c) 2022, kaydxh 3 * 4 *Permission is hereby granted, free of charge, to any person obtaining a copy 5 *of this software and associated documentation files (the "Software"), to deal 6 *in the Software without restriction, including without limitation the rights 7 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 *copies of the Software, and to permit persons to whom the Software is 9 *furnished to do so, subject to the following conditions: 10 * 11 *The above copyright notice and this permission notice shall be included in all 12 *copies or substantial portions of the Software. 13 * 14 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 *SOFTWARE. 21 */ 22 package instance 23 24 import "time" 25 26 func WithName(name string) PoolOption { 27 return PoolOptionFunc(func(p *Pool) { 28 p.opts.name = name 29 }) 30 } 31 32 func WithResevePoolSizePerCore(resevePoolSizePerCore int64) PoolOption { 33 return PoolOptionFunc(func(p *Pool) { 34 p.opts.resevePoolSizePerCore = resevePoolSizePerCore 35 }) 36 } 37 38 func WithCapacityPoolSizePerCore(capacityPoolSizePerCore int64) PoolOption { 39 return PoolOptionFunc(func(p *Pool) { 40 p.opts.capacityPoolSizePerCore = capacityPoolSizePerCore 41 }) 42 } 43 44 func WithWaitTimeoutOnce(waitTimeout time.Duration) PoolOption { 45 return PoolOptionFunc(func(p *Pool) { 46 p.opts.waitTimeoutOnce = waitTimeout 47 }) 48 } 49 50 func WithWaitTimeoutTotal(waitTimeout time.Duration) PoolOption { 51 return PoolOptionFunc(func(p *Pool) { 52 p.opts.waitTimeoutTotal = waitTimeout 53 }) 54 } 55 56 func WithLoadBalanceMode(loadBalanceMode LoadBalanceMode) PoolOption { 57 return PoolOptionFunc(func(p *Pool) { 58 p.opts.loadBalanceMode = loadBalanceMode 59 }) 60 } 61 62 func WithCoreIDs(coreIDs []int64) PoolOption { 63 return PoolOptionFunc(func(p *Pool) { 64 p.opts.coreIDs = coreIDs 65 }) 66 } 67 68 func WithModelPaths(modelPaths []string) PoolOption { 69 return PoolOptionFunc(func(p *Pool) { 70 p.opts.modelPaths = modelPaths 71 }) 72 } 73 74 func WithBatchSize(batchSize int64) PoolOption { 75 return PoolOptionFunc(func(p *Pool) { 76 p.opts.batchSize = batchSize 77 }) 78 } 79 80 func WithGlobalInitFunc(f GlobalInitFunc) PoolOption { 81 return PoolOptionFunc(func(p *Pool) { 82 p.opts.globalInitFunc = f 83 }) 84 } 85 86 func WithGlobalReleaseFunc(f GlobalReleaseFunc) PoolOption { 87 return PoolOptionFunc(func(p *Pool) { 88 p.opts.globalReleaseFunc = f 89 }) 90 } 91 92 func WithLocalInitFunc(f LocalInitFunc) PoolOption { 93 return PoolOptionFunc(func(p *Pool) { 94 p.opts.localInitFunc = f 95 }) 96 } 97 98 func WithLocalReleaseFunc(f LocalReleaseFunc) PoolOption { 99 return PoolOptionFunc(func(p *Pool) { 100 p.opts.localReleaseFunc = f 101 }) 102 } 103 104 func WithDeleteFunc(f DeleteFunc) PoolOption { 105 return PoolOptionFunc(func(p *Pool) { 106 p.opts.deleteFunc = f 107 }) 108 } 109 110 func WithEnabledPrintCostTime(enabled bool) PoolOption { 111 return PoolOptionFunc(func(p *Pool) { 112 p.opts.enabledPrintCostTime = enabled 113 }) 114 }