Back to Lo

Core Channeldispatcher

docs/data/core-channeldispatcher.md

1.53.0334 B
Original Source

ChannelDispatcher distributes messages from a stream to multiple channels based on a strategy.

go
stream := make(chan int, 100)
for i := 0; i < 100; i++ {
    stream <- i
}
close(stream)

channels := lo.ChannelDispatcher(stream, 3, 10, lo.DispatchingStrategyRoundRobin[int])
// Returns 3 channels with round-robin distribution