1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

Make pool configurable

This commit is contained in:
Asim
2016-06-07 00:46:14 +01:00
parent 38a66817e6
commit 89401cbb95
5 changed files with 67 additions and 14 deletions

View File

@ -28,7 +28,7 @@ func newRpcClient(opt ...Option) Client {
rc := &rpcClient{
once: sync.Once{},
opts: opts,
pool: newPool(),
pool: newPool(opts.PoolSize, opts.PoolTTL),
}
c := Client(rc)
@ -178,9 +178,18 @@ func (r *rpcClient) stream(ctx context.Context, address string, req Request, opt
}
func (r *rpcClient) Init(opts ...Option) error {
size := r.opts.PoolSize
ttl := r.opts.PoolTTL
for _, o := range opts {
o(&r.opts)
}
// recreate the pool if the options changed
if size != r.opts.PoolSize || ttl != r.opts.PoolTTL {
r.pool = newPool(r.opts.PoolSize, r.opts.PoolTTL)
}
return nil
}