Documentation
¶
Index ¶
- type Counter
- type Limiter
- func (lim *Limiter) Clear(key string)
- func (lim *Limiter) ClearAll()
- func (lim *Limiter) Close()
- func (lim *Limiter) Dec(key string) bool
- func (lim *Limiter) DecBy(key string, val int64) bool
- func (lim *Limiter) Inc(key string) bool
- func (lim *Limiter) IncBy(key string, val int64) bool
- func (lim *Limiter) IsClosed() bool
- type List
- func (l *List) Empty()
- func (l *List) LEach(f func(int, interface{}) bool)
- func (l *List) LPop() interface{}
- func (l *List) LPush(v interface{})
- func (l *List) REach(f func(int, interface{}) bool)
- func (l *List) RPop() interface{}
- func (l *List) RPush(v interface{})
- func (l *List) ValueAt(i int) interface{}
- type Pool
- type TBucket
- func (tb *TBucket) Close() bool
- func (tb *TBucket) Empty()
- func (tb *TBucket) Fill()
- func (tb *TBucket) FillTo(n int64)
- func (tb *TBucket) GetTok() bool
- func (tb *TBucket) GetToks(n int64) bool
- func (tb *TBucket) IsClosed() bool
- func (tb *TBucket) IsPaused() bool
- func (tb *TBucket) Pause() bool
- func (tb *TBucket) Resume() bool
- type TBucketQ
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
func NewCounter ¶
func NewCounter() *Counter
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents a light-weight implementation of a doubly linked list.
To learn more about doubly linked lists, visit: https://en.wikipedia.org/wiki/Doubly_linked_list
func (*List) Empty ¶
func (l *List) Empty()
Empty removes all items from the List. After calling this function, the length of the list is 0.
func (*List) LEach ¶
LEach iterates over each item in the List, starting from the left-most node (the head).
The parameter "f" is a function that accepts the index of the node (zero-based), and the value of the current node. This function should return true to continue the iteration, or false to immediately stop and return from the LEach function.
func (*List) LPop ¶
func (l *List) LPop() interface{}
LPop removes the left-most node from the List (i.e. the head), and returns it's value.
func (*List) LPush ¶
func (l *List) LPush(v interface{})
LPush inserts the provided value to the left-most position in the list (the head position).
func (*List) REach ¶
REach iterates over each item in the List, starting from the right-most node (the tail).
The parameter "f" is a function that accepts the index of the node (zero-based), and the value of the current node. This function should return true to continue the iteration, or false to immediately stop and return from the REach function.
func (*List) RPop ¶
func (l *List) RPop() interface{}
RPop removes the right-most node from the List (i.e. the tail), and returns it's value.
type TBucket ¶
type TBucket struct {
// contains filtered or unexported fields
}
TBucket is a struct representing the token bucket algorithm.
All provided functions are safe for concurrent use. It is designed to be a fast, lightweight, and lock-free implementation of the token bucket algorithm.
For more information on the token bucket algorithm, visit: https://en.wikipedia.org/wiki/Token_bucket
func NewBurstyTBucket ¶
NewBurstyTBucket will create a new token bucket instance.
The parameter "bsize" is the maximum bucket size and the parameter "burst" is the number of tokens to be added to the bucket every time interval "dur".
To learn more about the token bucket algorithm, check out: https://en.wikipedia.org/wiki/Token_bucket
func NewTBucket ¶
NewTBucket will create a new token bucket instance.
The parameter "bsize" is the maximum bucket size and the parameter "dur" is the time interval another token will be added to the bucket. Using this function is equivilant to calling NewBurstyTBucket(bsize, 1, dur).
To learn more about the token bucket algorithm, visit: https://en.wikipedia.org/wiki/Token_bucket
func (*TBucket) Close ¶
Close stops the internal ticker that adds tokens. The TBucket instance is now permanently closed and cannpt be reopened. When the TBucket will no longer be used, this function must be called to stop the internal timer from continuing to fire.
It returns true if the TBucket has been closed, or false if the TBucket has already been closed.
func (*TBucket) Empty ¶
func (tb *TBucket) Empty()
Empty removes all tokens from the bucket. This function does not stop the timer that adds new tokens to the bucket.
func (*TBucket) Fill ¶
func (tb *TBucket) Fill()
Fill adds the maximum amount of tokens to the bucket (fills the bucket) according to the defined bucket size.
func (*TBucket) FillTo ¶
FillTo adds "n" tokens to the bucket. The value "n" may be larger than the defined bucket size.
func (*TBucket) GetTok ¶
GetTok attempts to retrieve a single token from the bucket.
It returns true if a token has been successfully retrieved, or returns false if no token is available (the bucket is empty).
func (*TBucket) GetToks ¶
GetToks attempts to retrieve "n" tokens from the bucket.
It returns true if "n" tokens have been successfully retrieved, or returns false if there are not enough tokens available.
The provided parameter "n" cannot be smaller than 1. If a smaller value is provided, the value 1 will be used.
func (*TBucket) IsClosed ¶
IsClosed returns true if the TBucket has been closed. It returns false if it is still open.
func (*TBucket) IsPaused ¶
IsPaused returns true if the TBucket has been paused. It returns false if it is not in a paused state.
func (*TBucket) Pause ¶
Pause temporarily pauses the TBucket from adding new tokens to the bucket. When paused, tokens in the bucket can still be retrieved with GetTok or GetToks. The TBucket can be closed (with Close) or can be resumed (with Resume).
This function should be used when the TBucket should only be temporarily paused. If the TBucket will not be used again, Close should be called to stop the internal timer.
Pause returns true if the TBucket has been paused, or false if the TBucket is already in a paused state.
type TBucketQ ¶
type TBucketQ struct {
// contains filtered or unexported fields
}
func NewBurstyTBucketQ ¶
func NewTBucketQ ¶
return a new token bucket with the specified maximum bucket size (burst), the time interval for each new token, and the maximum size of the queue
func (*TBucketQ) Close ¶
Close stops the internal ticker that adds tokens. The TBucketQ instance is now permanently closed and cannpt be reopened. When the TBucketQ will no longer be used, this function must be called to stop the internal timer from continuing to fire.
It returns true if the TBucketQ has been closed, or false if the TBucketQ has already been closed.
func (*TBucketQ) GetToksNow ¶
func (*TBucketQ) IsClosed ¶
IsClosed returns true if the TBucketQ has been closed. It returns false if it is still open.
func (*TBucketQ) IsPaused ¶
IsPaused returns true if the TBucketQ has been paused. It returns false if it is not in a paused state.
func (*TBucketQ) Pause ¶
Pause temporarily pauses the TBucketQ from adding new tokens to the bucket. When paused, tokens in the bucket can still be retrieved with GetTok or GetToks. The TBucketQ can be closed (with Close) or can be resumed (with Resume).
This function should be used when the TBucketQ should only be temporarily paused. If the TBucketQ will not be used again, Close should be called to stop the internal timer.
Pause returns true if the TBucketQ has been paused, or false if the TBucketQ is already in a paused state.