throttle

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package throttle allows for throttling iterators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Iteration

func Iteration[Value any](strategy Strategy) func(iter.Seq[Value]) iter.Seq[Value]

Iteration throttles the iteration of another sequence via the given strategy.

Finiteness and reusability depend on the underlying sequence.

func Iteration2

func Iteration2[First any, Second any](strategy Strategy) func(iter.Seq2[First, Second]) iter.Seq2[First, Second]

Iteration2 throttles the iteration of another sequence via the given strategy.

Finiteness and reusability depend on the underlying sequence.

Types

type IterationsPerInterval

type IterationsPerInterval struct {
	// Maximum is the maximum amount of iterations allowed within the timespan defined by Interval.
	// Must be > 0.
	Maximum int

	// Timeframe defines the timespan during which at most Maximum iterations may be invoked.
	// Must be > 0.
	Timeframe time.Duration
}

IterationsPerInterval is a blueprint for creating throttling strategies that pass at most a certain number of items within a given timeframe from a sequence.

func (IterationsPerInterval) Strategy

func (strategyBlueprint IterationsPerInterval) Strategy() (Strategy, error)

Strategy creates a strategy with the configuration from the blueprint. The Strategy is independent from the blueprint afterwards.

type Strategy

type Strategy interface {
	// Waiter creates a Waiter. A Waiter should be independent from other Waiters created from the same Strategy.
	Waiter() Waiter
}

Strategy describes how throttling is done.

type Waiter

type Waiter interface {
	// Wait waits until the next iteration may be invoked. It is called before every yield.
	Wait()
}

type WaiterFunc

type WaiterFunc func()

WaiterFunc wraps a function to implement Waiter.

func (WaiterFunc) Wait

func (f WaiterFunc) Wait()

Wait waits by calling f.

Jump to

Keyboard shortcuts

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