Documentation ¶
Index ¶
- Constants
- Variables
- type Event
- type ExpireFunc
- type Timer
- func (t *Timer) Add(ttl time.Duration, fn ExpireFunc) *Event
- func (t *Timer) Del(event *Event)
- func (t *Timer) Events() []*Event
- func (t *Timer) Init(cap int)
- func (t *Timer) IsStopped() bool
- func (t *Timer) Len() int
- func (t *Timer) Set(event *Event, ttl time.Duration) bool
- func (t *Timer) Start() error
- func (t *Timer) Stop() error
Constants ¶
View Source
const ( // InfiniteDuration is the default time that timer bLocks. InfiniteDuration = time.Duration(1<<63 - 1) )
Variables ¶
View Source
var ( // DefaultAllocCap is the expanding capicity when the timer has no capicity to store more events. DefaultAllocCap = 1024 // ErrStarted represents timer has started ErrStarted = errors.New("timer has started") // ErrNotStarted represents timer has not started ErrNotStarted = errors.New("timer has not started") // ErrStopped represents timer has stopped ErrStopped = errors.New("timer has stopped") )
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
An Event represents an elemenet of the events in the timer.
type ExpireFunc ¶
type ExpireFunc func()
ExpireFunc represents a function will be executed when a event is trigged.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
A Timer represents a set that manage events which is related with time. It uses min-heap structure to orginaze and handle events.
func NewWithCap ¶
NewWithCap returns an timer instance with the given allocate capicity
func (*Timer) Add ¶
func (t *Timer) Add(ttl time.Duration, fn ExpireFunc) *Event
Add is used to add new event
Click to show internal directories.
Click to hide internal directories.