debouncer

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SleepContext

func SleepContext(ctx context.Context, dur time.Duration) error

SleepContext sleeps for the provided duration unless the context is cancelled first. An error is returned if the context is cancelled.

func SleepContextOrInterrupt

func SleepContextOrInterrupt[T any](ctx context.Context, dur time.Duration, ch <-chan T) (*T, error)

SleepContextOrInterrupt sleeps for a given duration unless interrupted by a message on the given channel.

Types

type Debouncer

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

Debouncer is a name taken from JavaScript Reactive programming. It allows firing many events in succession but only triggering one output event.

func NewDebouncer

func NewDebouncer(delay time.Duration) *Debouncer

NewDebouncer creates a new debouncer that ensures at least [delay] time period has occurred before triggering an output event.

func (*Debouncer) Listen

func (d *Debouncer) Listen(ctx context.Context, action func() error) error

Listen calls action based on the trigger events.

func (*Debouncer) Trigger

func (d *Debouncer) Trigger()

Trigger is the input event that causes a debounce action to occur (in wait).

Jump to

Keyboard shortcuts

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