github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/blog/content/context/interface.go (about) 1 // +build OMIT 2 3 package context 4 5 import "time" 6 7 // A Context carries a deadline, cancelation signal, and request-scoped values 8 // across API boundaries. Its methods are safe for simultaneous use by multiple 9 // goroutines. 10 type Context interface { 11 // Done returns a channel that is closed when this Context is canceled 12 // or times out. 13 Done() <-chan struct{} 14 15 // Err indicates why this context was canceled, after the Done channel 16 // is closed. 17 Err() error 18 19 // Deadline returns the time when this Context will be canceled, if any. 20 Deadline() (deadline time.Time, ok bool) 21 22 // Value returns the value associated with key or nil if none. 23 Value(key interface{}) interface{} 24 } 25 26 // WithCancel returns a copy of parent whose Done channel is closed as soon as 27 // parent.Done is closed or cancel is called. 28 func WithCancel(parent Context) (ctx Context, cancel CancelFunc) 29 30 // A CancelFunc cancels a Context. 31 type CancelFunc func() 32 33 // WithTimeout returns a copy of parent whose Done channel is closed as soon as 34 // parent.Done is closed, cancel is called, or timeout elapses. The new 35 // Context's Deadline is the sooner of now+timeout and the parent's deadline, if 36 // any. If the timer is still running, the cancel function releases its 37 // resources. 38 func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) 39 40 // WithValue returns a copy of parent whose Value method returns val for key. 41 func WithValue(parent Context, key interface{}, val interface{}) Context 42 43 // Background returns an empty Context. It is never canceled, has no deadline, 44 // and has no values. Background is typically used in main, init, and tests, 45 // and as the top-level Context for incoming requests. 46 func Background() Context