X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9e27ddfd2f2538ff2216d75c450aa72dd3bc1cf8..c2d2234ce0da91881fc63459a30c5efcfbe29a26:/sdk/go/arvadosclient/pool.go diff --git a/sdk/go/arvadosclient/pool.go b/sdk/go/arvadosclient/pool.go index 26b3518798..bb7867aef7 100644 --- a/sdk/go/arvadosclient/pool.go +++ b/sdk/go/arvadosclient/pool.go @@ -1,7 +1,13 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + package arvadosclient import ( "sync" + + "git.arvados.org/arvados.git/sdk/go/arvados" ) // A ClientPool is a pool of ArvadosClients. This is useful for @@ -10,7 +16,7 @@ import ( // credentials. See arvados-git-httpd for an example, and sync.Pool // for more information about garbage collection. type ClientPool struct { - // Initialize new clients by coping this one. + // Initialize new clients by copying this one. Prototype *ArvadosClient pool *sync.Pool @@ -21,9 +27,22 @@ type ClientPool struct { // MakeClientPool returns a new empty ClientPool, using environment // variables to initialize the prototype. func MakeClientPool() *ClientPool { - proto, err := MakeArvadosClient() + return MakeClientPoolWith(nil) +} + +// MakeClientPoolWith returns a new empty ClientPool with a previously +// initialized arvados.Client. +func MakeClientPoolWith(client *arvados.Client) *ClientPool { + var err error + var proto *ArvadosClient + + if client == nil { + proto, err = MakeArvadosClient() + } else { + proto, err = New(client) + } return &ClientPool{ - Prototype: &proto, + Prototype: proto, lastErr: err, } }