| 348 | } |
| 349 | |
| 350 | func (r *rpcClient) Init(opts ...Option) error { |
| 351 | r.mu.Lock() |
| 352 | defer r.mu.Unlock() |
| 353 | |
| 354 | size := r.opts.PoolSize |
| 355 | ttl := r.opts.PoolTTL |
| 356 | tr := r.opts.Transport |
| 357 | |
| 358 | for _, o := range opts { |
| 359 | o(&r.opts) |
| 360 | } |
| 361 | |
| 362 | // update pool configuration if the options changed |
| 363 | if size != r.opts.PoolSize || ttl != r.opts.PoolTTL || tr != r.opts.Transport { |
| 364 | // close existing pool |
| 365 | if err := r.pool.Close(); err != nil { |
| 366 | return errors.Wrap(err, "failed to close pool") |
| 367 | } |
| 368 | |
| 369 | // create new pool |
| 370 | r.pool = pool.NewPool( |
| 371 | pool.Size(r.opts.PoolSize), |
| 372 | pool.TTL(r.opts.PoolTTL), |
| 373 | pool.Transport(r.opts.Transport), |
| 374 | pool.CloseTimeout(r.opts.PoolCloseTimeout), |
| 375 | ) |
| 376 | } |
| 377 | |
| 378 | return nil |
| 379 | } |
| 380 | |
| 381 | // Options retrives the options. |
| 382 | func (r *rpcClient) Options() Options { |