Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeadlineRunner ¶
type DeadlineRunner struct {
// contains filtered or unexported fields
}
DeadlineRunner runs a callback function in a goroutine whenever the deadline is reached. The function is called at most once per call to SetDeadline.
Multiple executions of the callback can happen at once, so the callback must ensure proper synchronization.
SetDeadline is safe to call from multiple goroutines.
func NewDeadlineRunner ¶
func NewDeadlineRunner(f func()) *DeadlineRunner
func (*DeadlineRunner) SetDeadline ¶
func (r *DeadlineRunner) SetDeadline(deadline time.Time)
type Monitor ¶
type Monitor interface { // WithDeadline creates a context similarly to context.WithDeadline, except // the newly created context is also subject to any deadlines set by // SetDeadline. WithDeadline(ctx context.Context, deadline time.Time) (context.Context, context.CancelFunc) // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). WithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc) // SetDeadline sets an absolute time after which all tracked contexts are // canceled. SetDeadline can be set in the past to mark everything as // done, or can be extended in the future through repeated calls. // // A 0 value for the deadline means contexts will never be canceled by the monitor. SetDeadline(deadline time.Time) // Count returns the number of contexts in the monitor that haven't expired or // been canceled yet. Count() int }
Monitor implements deadline-aware context creation. Implementations guarantee that any contexts returned by the methods are cancelled when the deadline passed in through SetDeadline is reached. Any change to deadline is respected, including setting it into the past.
Monitor is targeted for use in libraries that implement both deadline-aware logic (e.g., net.Conn and net.PacketConn implementations), but also have context-aware internals.
IMPORTANT: If the deadline set through SetDeadline is reached and a context is canceled, the error will be context.Canceled instead of context.DeadlineExceeded.
func NewMonitor ¶
func NewMonitor() Monitor
Directories ¶
Path | Synopsis |
---|---|
Package mock_ctxmonitor is a generated GoMock package.
|
Package mock_ctxmonitor is a generated GoMock package. |