Documentation
¶
Index ¶
Constants ¶
const DEFAULT_POPPER_RESOLUTION = 100 * time.Millisecond
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Prison ¶
type Prison[K comparable] struct { // contains filtered or unexported fields }
Prison takes care of its prisoners (items) and their executions (timeouts). Prison is the main structure in this package. It contains a priority queue based on the deadlines of its items as well as backreferences to the items in the queue, which makes accessing the dead items as well as specific items easy and efficient
func NewPrison ¶
func NewPrison[K comparable]() *Prison[K]
NewPrison creates new Prison without any items
func (*Prison[K]) Drop ¶
func (p *Prison[K]) Drop(itemID K)
Drop removes an item from the Prison. It doesn't have to be expired
func (*Prison[K]) Pop ¶
Pop pops all expired items in Prison. If there are no such items, it returns empty slice
func (*Prison[K]) Popper ¶
Popper is the same as PopperWithResolution but with the default resolution.
func (*Prison[K]) PopperWithResolution ¶
func (p *Prison[K]) PopperWithResolution(ctx context.Context, resolution time.Duration) <-chan Item[K]
PopperWithResolution returns a new channel into which newly expired popped items are periodically (every `resolution`) pushed. This loop ends when `ctx` is cancelled