7 // A ClientPool is a pool of ArvadosClients. This is useful for
8 // applications that make API calls using a dynamic set of tokens,
9 // like web services that pass through their own clients'
10 // credentials. See arvados-git-httpd for an example, and sync.Pool
11 // for more information about garbage collection.
12 type ClientPool struct {
13 // Initialize new clients by coping this one.
14 Prototype *ArvadosClient
21 // MakeClientPool returns a new empty ClientPool, using environment
22 // variables to initialize the prototype.
23 func MakeClientPool() *ClientPool {
24 proto, err := MakeArvadosClient()
31 func (p *ClientPool) setup() {
32 p.pool = &sync.Pool{New: func() interface{} {
41 // Err returns the error that was encountered last time Get returned
43 func (p *ClientPool) Err() error {
47 // Get returns an ArvadosClient taken from the pool, or a new one if
48 // the pool is empty. If an existing client is returned, its state
49 // (including its ApiToken) will be just as it was when it was Put
51 func (p *ClientPool) Get() *ArvadosClient {
52 p.setupOnce.Do(p.setup)
53 c, ok := p.pool.Get().(*ArvadosClient)
60 // Put puts an ArvadosClient back in the pool.
61 func (p *ClientPool) Put(c *ArvadosClient) {
62 p.setupOnce.Do(p.setup)