Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelDelayer ¶
type ChannelDelayer[T any] struct { // contains filtered or unexported fields }
ChannelDelayer provides a mechanism to inject delay in a channel.
Algorithm sketch: When an element arrives from the input channel, attach the current timestamp and put it in a queue. The top of the queue is checked, if the element has stayed in the queue for more than `delayBy`, then the element in popped and sent to the output channel.
func NewChannelDelayer ¶
func NewChannelDelayer[T any]( delayBy time.Duration, in <-chan T, queueSize int, outChSize int, ) *ChannelDelayer[T]
NewChannelDelayer creates a new ChannelDelayer.
func (*ChannelDelayer[T]) Close ¶
func (d *ChannelDelayer[T]) Close()
Close closes the ChannelDelayer.
func (*ChannelDelayer[T]) Out ¶
func (d *ChannelDelayer[T]) Out() <-chan T
Out returns the delayed channel. The downstream logic should read from Out().
Click to show internal directories.
Click to hide internal directories.