Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func FairDivider ¶ added in v1.0.0
Distributes quantity evenly among the priorities.
Used for equaling.
Example results:
- 6 / [3 2 1] = map[3:2, 2:2, 1:2]
- 100 / [70 20 10] = map[70:34, 20:33, 10:33]
func RateDivider ¶ added in v1.0.0
Distributes quantity between priorities in proportion to the priority value.
Used for prioritization.
Example results:
- 6 / [3 2 1] = map[3:3, 2:2, 1:1]
- 100 / [70 20 10] = map[70:70, 20:20, 10:10]
Types ¶
type Discipline ¶
type Discipline[Type any] struct { // contains filtered or unexported fields }
Main prioritization discipline.
Preferably input channels should be buffered for performance reasons.
Data from input channels passed to handlers by output channel.
Handlers must write priority of processed data to feedback channel after it has been processed.
For equaling use FairDivider, for prioritization use RateDivider or custom divider
func New ¶
func New[Type any](opts Opts[Type]) (*Discipline[Type], error)
Creates and runs main prioritization discipline
func (*Discipline[Type]) AddInput ¶
func (dsc *Discipline[Type]) AddInput(channel chan Type, priority uint)
Adds or updates (if it added previously) input channel for specified priority
func (*Discipline[Type]) RemoveInput ¶
func (dsc *Discipline[Type]) RemoveInput(priority uint)
Removes input channel for specified priority
func (*Discipline[Type]) Stop ¶
func (dsc *Discipline[Type]) Stop()
Terminates work of the discipline
type Divider ¶ added in v1.0.0
Distributes quantity of something by priorities. Determines how handlers are distributed among priorities.
Slice of priorities is passed to this function sorted from highest to lowest.
Sum of the distributed quantities must equal the original quantity.
If distribution is nil then it must be created and returned, otherwise it must be updated and returned.
type Opts ¶
type Opts[Type any] struct { // Determines how handlers are distributed among priorities Divider Divider // Handlers must write priority of processed data to feedback channel after it has been processed Feedback <-chan uint // Between how many handlers you need to distribute data HandlersQuantity uint // Channels with input data, should be buffered for performance reasons. Map key is a value of priority Inputs map[uint]<-chan Type // Handlers should read distributed data from this channel Output chan<- Prioritized[Type] }
Options of the created main prioritization discipline
type Prioritized ¶ added in v1.0.0
Describes the data distributed by the prioritization discipline