Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub[F any] struct { // contains filtered or unexported fields }
Hub is a simple load balancer that distributes work across a set of routees (workers). It supports different routing strategies, such as round-robin and random selection. The Next method returns the next routee according to the configured strategy. The Broadcast method applies a function to all routees sequentially, while FanOut does so concurrently.
func NewRandom ¶
NewRandom creates a new Hub that uses random selection to distribute work across the given routees.
func NewRoundRobin ¶
NewRoundRobin creates a new Hub that uses round-robin routing to distribute work across the given routees.
func (*Hub[F]) Broadcast ¶
func (h *Hub[F]) Broadcast(fn func(F))
Broadcast applies the given function to all routees sequentially.
func (*Hub[F]) FanOut ¶
func (h *Hub[F]) FanOut(fn func(F))
FanOut applies the given function to all routees concurrently.
func (*Hub[F]) FanOutWait ¶
func (h *Hub[F]) FanOutWait(fn func(F))
FanOutWait applies the given function to all routees concurrently and waits for all of them to complete before returning.
func (*Hub[F]) Next ¶
func (h *Hub[F]) Next() F
Next returns the next routee according to the configured routing strategy.