chanutil

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MPL-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DebouncedChan

type DebouncedChan struct {
	// contains filtered or unexported fields
}

DebouncedChan is a channel that will only fire once per cooldown period, at the leading edge. If it is called again during the cooldown, the subsequent calls are delayed until the cooldown period has elapsed and are also coalesced into a single call.

func NewDebouncedChan

func NewDebouncedChan(ctx context.Context, cooldown time.Duration, sendLeading bool) *DebouncedChan

NewDebouncedChan returns a new DebouncedChan which sends on the channel no more often than the cooldown period.

If sendLeading is true, the channel will signal once on C the first time it receives a signal, then again once per cooldown period. If sendLeading is false, the initial signal isn't sent.

func (*DebouncedChan) C

func (d *DebouncedChan) C() <-chan struct{}

C is the debounced channel. Multiple invocations to Call during the cooldown period will deduplicate to a single emission on this channel on the period's leading edge (if sendLeading was enabled), and one more on the trailing edge for as many periods as invocations continue to come in.

func (*DebouncedChan) Call

func (d *DebouncedChan) Call()

Call invokes the debounced channel, and is the call which will be debounced. If multiple invocations of this function are made during the cooldown period, they'll be debounced to a single emission on C on the period's leading edge (if sendLeading is enabled), and then one fire on the trailing edge of each period for as long as Call continues to be invoked. If a timer period elapses without an invocation on Call, the timer is stopped and behavior resets the next time Call is invoked again.

Jump to

Keyboard shortcuts

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