Documentation ¶
Index ¶
- type C
- type CallbackFunc
- type LessFunc
- type Schedule
- type Stack
- func (s *Stack) Insert(t time.Time, x interface{}) (match interface{})
- func (s *Stack) Len() (n int)
- func (s *Stack) MinTime() (t time.Time)
- func (s *Stack) Pop() (x interface{})
- func (s *Stack) Prune(t time.Time) (S []interface{})
- func (s *Stack) Remove(t time.Time, x interface{}) (match interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type C ¶
type C struct {
// contains filtered or unexported fields
}
C converts timeouts to cancellation. This simulates the behaviour of other objects with a SetDeadline method, but using a cancellation function. SetDeadline should be called before each call to WithCancel, just as when working with, for example, an os.File, SetDeadline should be called prior to each call to Read. For example, one can use a context and its cancel function:
ctx, cancel := context.WithCancel(parentContext) cancellable := timeutil.NewCancellable(cancel) defer cancellable.Stop() cancellable.SetDeadline(deadline) cancellable.WithCancel(func() error { // do something or other // checking ctx for cancellation // The context ctx will fire if the deadline is exceeded. })
func NewCancellable ¶
func NewCancellable(cancel context.CancelFunc) *C
NewCancellable creates a new C, starting a background worker handling timeouts. The user must call Stop, otherwise resources will leak. See the documentation for C for further discussion and example usage.
func (*C) SetDeadline ¶
SetDeadline sets the deadline for future WithCancel calls and any currently-blocked WithCancel calls. A zero value for t means WithCancel will not time out.
func (*C) WithCancel ¶
WithCancel permits the wrapped cancel function to be called whilst executing f.
type CallbackFunc ¶
type CallbackFunc func(x interface{})
CallbackFunc is the function that will be called on timeout.
type LessFunc ¶
type LessFunc func(x interface{}, y interface{}) bool
LessFunc returns true iff x < y.
type Schedule ¶
type Schedule struct {
// contains filtered or unexported fields
}
Schedule automates calling a callback function at certain times, with certain data.
func NewSchedule ¶
func NewSchedule(f CallbackFunc, less LessFunc) *Schedule
NewSchedule returns a new Schedule with given callback function. Note: There is currently no way to stop the background workers associated with a Schedule.
func (*Schedule) Insert ¶
Insert adds the item x to be passed to the callback function at time t. If a matching item already exists at that time position, it will be replaced and the matching item returned.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a stack of user items, ordered by time.
func (*Stack) Insert ¶
Insert inserts the item x in the stack at time t. If a matching item already exists at that time position, it will be replaced and the matching item returned.
func (*Stack) MinTime ¶
MinTime returns the earliest time for an item in the stack. If the stack is empty, this returns the zero time.
func (*Stack) Pop ¶
func (s *Stack) Pop() (x interface{})
Pop pops the earliest item off the stack. If the stack is empty, this returns nil.