chanutil

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

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 function that will only be called 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