chdelay

package
v0.0.0-...-f79c7ce Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

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().

Jump to

Keyboard shortcuts

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