eventcounter

package
v2.5.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2019 License: Apache-2.0 Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventCounter

type EventCounter struct {
	// contains filtered or unexported fields
}

EventCounter is used to track events over time, potentially allowing you to limit them per time period

func New

func New(now time.Time, duration time.Duration) EventCounter

New returns a new EventCounter object that resets event counts per duration.

func (*EventCounter) Event

func (a *EventCounter) Event(now time.Time) int64

Event returns the number of events in the time period now. Note, now should be >= the last event threshold. Also, we avoid any loops with compare and swap atomics because we're ok being off a few items as long as we're generally accurate and fast.

func (*EventCounter) Events

func (a *EventCounter) Events(now time.Time, count int64) int64

Events behaves just like Event() but acts on multiple events at once to reduce the number of atomic increment calls

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL