7 // Context is an copy of the Go v1.7 stdlib's context.Context interface.
8 // It is represented as a SDK interface to enable you to use the "WithContext"
9 // API methods with Go v1.6 and a Context type such as golang.org/x/net/context.
11 // See https://golang.org/pkg/context on how to use contexts.
12 type Context interface {
13 // Deadline returns the time when work done on behalf of this context
14 // should be canceled. Deadline returns ok==false when no deadline is
15 // set. Successive calls to Deadline return the same results.
16 Deadline() (deadline time.Time, ok bool)
18 // Done returns a channel that's closed when work done on behalf of this
19 // context should be canceled. Done may return nil if this context can
20 // never be canceled. Successive calls to Done return the same value.
21 Done() <-chan struct{}
23 // Err returns a non-nil error value after Done is closed. Err returns
24 // Canceled if the context was canceled or DeadlineExceeded if the
25 // context's deadline passed. No other values for Err are defined.
26 // After Done is closed, successive calls to Err return the same value.
29 // Value returns the value associated with this context for key, or nil
30 // if no value is associated with key. Successive calls to Value with
31 // the same key returns the same result.
33 // Use context values only for request-scoped data that transits
34 // processes and API boundaries, not for passing optional parameters to
36 Value(key interface{}) interface{}
39 // BackgroundContext returns a context that will never be canceled, has no
40 // values, and no deadline. This context is used by the SDK to provide
41 // backwards compatibility with non-context API operations and functionality.
44 // This context function is equivalent to context.Background in the Go stdlib.
47 // The context returned will be the value returned by context.Background()
49 // See https://golang.org/pkg/context for more information on Contexts.
50 func BackgroundContext() Context {
54 // SleepWithContext will wait for the timer duration to expire, or the context
55 // is canceled. Which ever happens first. If the context is canceled the Context's
56 // error will be returned.
58 // Expects Context to always return a non-nil error if the Done channel is closed.
59 func SleepWithContext(ctx Context, dur time.Duration) error {
60 t := time.NewTimer(dur)