Documentation ¶
Index ¶
- Variables
- type Bucket
- type BucketInterface
- type Cache
- type CacheOption
- type Execute
- type Numerical
- type Queue
- type Ring
- type RollingWindow
- type RollingWindowOption
- type SafeMap
- type Set
- func (s *Set) Add(i ...any)
- func (s *Set) AddInt(ii ...int)
- func (s *Set) AddInt64(ii ...int64)
- func (s *Set) AddStr(ss ...string)
- func (s *Set) AddUint(ii ...uint)
- func (s *Set) AddUint64(ii ...uint64)
- func (s *Set) Contains(i any) bool
- func (s *Set) Count() int
- func (s *Set) Keys() []any
- func (s *Set) KeysInt() []int
- func (s *Set) KeysInt64() []int64
- func (s *Set) KeysStr() []string
- func (s *Set) KeysUint() []uint
- func (s *Set) KeysUint64() []uint64
- func (s *Set) Remove(i any)
- type TimingWheel
Constants ¶
This section is empty.
Variables ¶
var ( ErrClosed = errors.New("TimingWheel is closed already") ErrArgument = errors.New("incorrect task argument") )
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket[T Numerical] struct { Sum T Count int64 }
Bucket defines the bucket that holds sum and num of additions.
type BucketInterface ¶
type BucketInterface[T Numerical] interface { Add(v T) Reset() }
BucketInterface is the interface that defines the buckets.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
A Cache object is an in-memory cache.
func NewCache ¶
func NewCache(expire time.Duration, opts ...CacheOption) (*Cache, error)
NewCache returns a Cache with given expire.
func (*Cache) SetWithExpire ¶
SetWithExpire sets value into c with key and expire with the given value.
type CacheOption ¶
type CacheOption func(cache *Cache)
CacheOption defines the method to customize a Cache.
func WithLimit ¶
func WithLimit(limit int) CacheOption
WithLimit customizes a Cache with items up to limit.
func WithName ¶
func WithName(name string) CacheOption
WithName customizes a Cache with the given name.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
A Queue is a FIFO queue.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
A Ring can be used as fixed size ring.
type RollingWindow ¶
type RollingWindow[T Numerical, B BucketInterface[T]] struct { // contains filtered or unexported fields }
RollingWindow defines a rolling window to calculate the events in buckets with the time interval.
func NewRollingWindow ¶
func NewRollingWindow[T Numerical, B BucketInterface[T]](newBucket func() B, size int, interval time.Duration, opts ...RollingWindowOption[T, B]) *RollingWindow[T, B]
NewRollingWindow returns a RollingWindow that with size buckets and time interval, use opts to customize the RollingWindow.
type RollingWindowOption ¶
type RollingWindowOption[T Numerical, B BucketInterface[T]] func(rollingWindow *RollingWindow[T, B])
RollingWindowOption let callers customize the RollingWindow.
func IgnoreCurrentBucket ¶
func IgnoreCurrentBucket[T Numerical, B BucketInterface[T]]() RollingWindowOption[T, B]
IgnoreCurrentBucket lets the Reduce call ignore current bucket.
type SafeMap ¶
type SafeMap struct {
// contains filtered or unexported fields
}
SafeMap provides a map alternative to avoid memory leak. This implementation is not needed until issue below fixed. https://github.com/golang/go/issues/20135
func (*SafeMap) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is not thread-safe, for concurrent use, make sure to use it with synchronization.
func NewSet ¶
func NewSet() *Set
NewSet returns a managed Set, can only put the values with the same type.
func NewUnmanagedSet ¶
func NewUnmanagedSet() *Set
NewUnmanagedSet returns an unmanaged Set, which can put values with different types.
type TimingWheel ¶
type TimingWheel struct {
// contains filtered or unexported fields
}
A TimingWheel is a timing wheel object to schedule tasks.
func NewTimingWheel ¶
NewTimingWheel returns a TimingWheel.
func NewTimingWheelWithTicker ¶
func NewTimingWheelWithTicker(interval time.Duration, numSlots int, execute Execute, ticker timex.Ticker) (*TimingWheel, error)
NewTimingWheelWithTicker returns a TimingWheel with the given ticker.
func (*TimingWheel) Drain ¶
func (tw *TimingWheel) Drain(fn func(key, value any)) error
Drain drains all items and executes them.
func (*TimingWheel) MoveTimer ¶
func (tw *TimingWheel) MoveTimer(key any, delay time.Duration) error
MoveTimer moves the task with the given key to the given delay.
func (*TimingWheel) RemoveTimer ¶
func (tw *TimingWheel) RemoveTimer(key any) error
RemoveTimer removes the task with the given key.
func (*TimingWheel) SetTimer ¶
func (tw *TimingWheel) SetTimer(key, value any, delay time.Duration) error
SetTimer sets the task value with the given key to the delay.
func (*TimingWheel) Stop ¶
func (tw *TimingWheel) Stop()
Stop stops tw. No more actions after stopping a TimingWheel.