Documentation
¶
Index ¶
- Variables
- type Aggregator
- func (a *Aggregator[K, T]) Debug() *Aggregator[K, T]
- func (a *Aggregator[K, T]) Query(key K) Result[T]
- func (a *Aggregator[K, T]) QueryChan(key K) <-chan Result[T]
- func (a *Aggregator[K, T]) QueryMulti(keys []K) []Result[T]
- func (a *Aggregator[K, T]) QueryResult(key K) (T, error)
- func (a *Aggregator[K, T]) QueryValue(key K) T
- func (a *Aggregator[K, T]) Run() (*Aggregator[K, T], error)
- func (a *Aggregator[K, T]) RunWithWorkers(workers int) (*Aggregator[K, T], error)
- type AggregatorList
- func (aggregators AggregatorList[K, T]) Query(key K) Result[T]
- func (aggregators AggregatorList[K, T]) QueryMulti(keys []K) []Result[T]
- func (aggregators AggregatorList[K, T]) QueryResult(key K) (T, error)
- func (aggregators AggregatorList[K, T]) QueryValue(key K) T
- func (aggregators AggregatorList[K, T]) Run() AggregatorList[K, T]
- type Result
Constants ¶
This section is empty.
Variables ¶
var NeverFlushTimeout time.Duration = -1
If NeverFlushTimeout is set for the flushMaxWait, the aggregator will never flush with timeout.
var NoResult = errors.New("No result")
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator[K comparable, T any] struct { // Max waiting time of worker to flush query tasks. MaxWait time.Duration // Max amount of query tasks, the worker will flush after reaching it. MaxSize int // contains filtered or unexported fields }
Aggregator is the instance, it contains the flush and worker settings. Create an instance of Aggregator, by using New()
func New ¶
func New[K comparable, T any](fn func([]K) (map[K]T, error), flushMaxWait time.Duration, flushMaxSize int) *Aggregator[K, T]
New creates a new Aggregator. The flushMaxWait variable sets the maximum timeout of flushing. If flushMaxWait equals to NeverFlushTimeout then the aggregator will never flush with timeout. The flushMaxSize variable sets the maximum size of task. If the flushMaxSize <= 0, the aggregator will never flush with amount of tasks.
func (*Aggregator[K, T]) Debug ¶
func (a *Aggregator[K, T]) Debug() *Aggregator[K, T]
If Debug() is called, the Aggregator will prints debug messages.
func (*Aggregator[K, T]) Query ¶
func (a *Aggregator[K, T]) Query(key K) Result[T]
Query with a key and return with a Result[T] synchronously. It is a shortcut for <-QueryChan(key)
func (*Aggregator[K, T]) QueryChan ¶
func (a *Aggregator[K, T]) QueryChan(key K) <-chan Result[T]
Query with a key and return with a Result[T] channel.
func (*Aggregator[K, T]) QueryMulti ¶
func (a *Aggregator[K, T]) QueryMulti(keys []K) []Result[T]
Query with multiple keys and return a slice of Result[T] synchronously.
func (*Aggregator[K, T]) QueryResult ¶
func (a *Aggregator[K, T]) QueryResult(key K) (T, error)
Query with a key and return with Value and Error of Result[T] synchronously. It is a shortcut for Query(key).Get()
func (*Aggregator[K, T]) QueryValue ¶
func (a *Aggregator[K, T]) QueryValue(key K) T
Query with a key and return with Value Result[T] synchronously. It is a shortcut for Query(key).Value
func (*Aggregator[K, T]) Run ¶
func (a *Aggregator[K, T]) Run() (*Aggregator[K, T], error)
Start run Aggregator with single worker.
func (*Aggregator[K, T]) RunWithWorkers ¶
func (a *Aggregator[K, T]) RunWithWorkers(workers int) (*Aggregator[K, T], error)
Start run Aggregator with n workers.
type AggregatorList ¶
type AggregatorList[K comparable, T any] []*Aggregator[K, T]
AggregatorList is a type defintion of []*Aggregator[K, T].
func NewList ¶
func NewList[K comparable, T any](aggregators ...*Aggregator[K, T]) AggregatorList[K, T]
NewList creates a new slice of Aggregators. When an aggregator returns a NoResult error it will call the next aggregator of the AggregatorList by order.
func (AggregatorList[K, T]) Query ¶
func (aggregators AggregatorList[K, T]) Query(key K) Result[T]
Query result in aggregators of the AggregatorList by order.
func (AggregatorList[K, T]) QueryMulti ¶
func (aggregators AggregatorList[K, T]) QueryMulti(keys []K) []Result[T]
Query result in aggregator of the AggregatorList by order with multiple keys and return a slice of Result[T] synchronously.
func (AggregatorList[K, T]) QueryResult ¶
func (aggregators AggregatorList[K, T]) QueryResult(key K) (T, error)
It is a shortcut for Query(key).Get()
func (AggregatorList[K, T]) QueryValue ¶
func (aggregators AggregatorList[K, T]) QueryValue(key K) T
It is a shortcut for Query(key).Value
func (AggregatorList[K, T]) Run ¶
func (aggregators AggregatorList[K, T]) Run() AggregatorList[K, T]
Run all aggregators of the AggregatorList by order.
type Result ¶
Result of Aggregator query. Including Value and Error.
func (Result[T]) IsNoResult ¶
Use to check Result[T].Error equals NoResult. If fn of aggregator does not set the key of result map or returns an NoResult error, the Result[T].Error will be NoResult.