Source file blog/context/interface.go

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

View as plain text