API: WithContext documentation

This commit is contained in:
diamondburned (Forefront) 2020-05-03 14:04:09 -07:00
parent a0bccd9c35
commit af682d3f35
2 changed files with 5 additions and 0 deletions

View File

@ -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),

View File

@ -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)