Skip to content

Commit

Permalink
clientv3: let user provide a client context through Config
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Feb 17, 2017
1 parent 5d3597a commit c9452c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (c *Client) dial(endpoint string, dopts ...grpc.DialOption) (*grpc.ClientCo
tokenMu: &sync.RWMutex{},
}

err := c.getToken(context.TODO())
err := c.getToken(c.ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -307,7 +307,12 @@ func newClient(cfg *Config) (*Client, error) {
}

// use a temporary skeleton client to bootstrap first connection
ctx, cancel := context.WithCancel(context.TODO())
baseCtx := context.TODO()
if cfg.Context != nil {
baseCtx = cfg.Context
}

ctx, cancel := context.WithCancel(baseCtx)
client := &Client{
conn: nil,
cfg: *cfg,
Expand Down
5 changes: 5 additions & 0 deletions clientv3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/tls"
"time"

"golang.org/x/net/context"
"google.golang.org/grpc"
)

Expand All @@ -43,4 +44,8 @@ type Config struct {

// DialOptions is a list of dial options for the grpc client (e.g., for interceptors).
DialOptions []grpc.DialOption

// Context is the default client context; it can be used to cancel grpc dial out and
// other operations that do not have an explicit context.
Context context.Context
}

0 comments on commit c9452c6

Please sign in to comment.