API Reference

p-debounce

Debounces an async function so bursts of calls collapse into a single promise-returning invocation.

Official Documentation ↗
CompatibilityThis documentation covers version v6.0.0. Check the official docs for the latest API surface.

Installation

npmnpm install p-debounce
pnpmpnpm add p-debounce
yarnyarn add p-debounce

Methods

Overview

p-debounce collapses rapid, repeated calls into one execution after a quiet period. Because it targets async functions, every caller gets a promise for the eventual result rather than a silent drop.

Core Methods

Call pDebounce with your async function and a wait time. The returned function can be awaited, and an options object selects leading behavior or a different debouncing strategy.

Usage Notes

Ideal for search-as-you-type, resize and scroll handlers that trigger network work. Combine with an AbortController so an in-flight request can be superseded by a newer one.

Common Pitfalls

Debouncing hides work from callers, so do not use it for operations that must each run, such as writes. Trailing-edge debounce delays the last call until activity stops, which can feel laggy if the wait is too long.

FAQ

How is p-debounce different from lodash debounce?
p-debounce is designed for async functions and returns promises, so callers can await the eventual result instead of relying on callbacks. It also supports leading and trailing invocation.
What happens to calls made during the quiet window?
They reset the timer and share the eventual invocation. Only the arguments of the last call are used when the function finally runs.
Can I cancel a pending debounce?
The returned function exposes cancellation in supported versions. If cancel is unavailable, guard inside the function against stale arguments instead.