debounce

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package debounce coalesces bursts of calls into one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

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

Func runs fn once, delay after the last Trigger: a burst of triggers (e.g. deleting a user's hundreds of nodes) costs one run, not one per trigger. With a maximum wait (WithMaxWait) it runs no later than that after the burst's first trigger: a steady stream of triggers runs it now and then rather than never.

func New

func New(delay time.Duration, fn func()) *Func

New creates a Func for fn.

func (*Func) Trigger

func (d *Func) Trigger()

Trigger (re)schedules fn to run delay from now (no later than the maximum wait after the burst's first trigger).

func (*Func) WithMaxWait

func (d *Func) WithMaxWait(maxWait time.Duration) *Func

WithMaxWait - d with the maximum wait after a burst's first trigger.

Jump to

Keyboard shortcuts

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