diff --git a/api/api.go b/api/api.go index c2c9689..6813b5a 100644 --- a/api/api.go +++ b/api/api.go @@ -49,6 +49,8 @@ func NewCustomClient(token string, httpClient *httputil.Client) *Client { } } +// WithContext returns a shallow copy of Client with the given context. It's +// used for method timeouts and such. This method is thread-safe. func (c *Client) WithContext(ctx context.Context) *Client { return &Client{ Client: c.Client.WithContext(ctx), diff --git a/state/state.go b/state/state.go index 6505422..47341a2 100644 --- a/state/state.go +++ b/state/state.go @@ -76,6 +76,9 @@ func NewFromSession(s *session.Session, store Store) (*State, error) { return state, state.hookSession() } +// WithContext returns a shallow copy of State with the context replaced in the +// API client. All methods called on the State will use this given context. This +// method is thread-safe. func (s *State) WithContext(ctx context.Context) *State { copied := *s copied.Client = copied.Client.WithContext(ctx)