Skip to content

fix: debounce flush should cancel pending invocation#475

Open
Yanhu007 wants to merge 1 commit into
sodiray:masterfrom
Yanhu007:fix/debounce-flush-cancel-timer
Open

fix: debounce flush should cancel pending invocation#475
Yanhu007 wants to merge 1 commit into
sodiray:masterfrom
Yanhu007:fix/debounce-flush-cancel-timer

Conversation

@Yanhu007

Copy link
Copy Markdown

Fixes #256

Problem

debounce.flush() calls the function immediately but does not cancel the pending debounced timer. This causes the function to execute twice — once from flush and once when the timer fires.

const fn = debounce({ delay: 100 }, callback)
fn()           // starts timer
fn.flush()     // calls immediately, but timer still pending!
// 100ms later: callback fires AGAIN

Fix

Clear the timer and reset it to undefined in flush() before calling the function. This matches lodash behavior where flush cancels the delayed invocation.

debounce.flush() calls the function immediately but does not
cancel the pending debounced invocation, causing the function
to execute twice — once from flush and once from the timer.

Clear the timer in flush() before calling the function, matching
the behavior of lodash's debounce.flush().

Fixes sodiray#256
@vercel

vercel Bot commented Apr 13, 2026

Copy link
Copy Markdown

@Yanhu007 is attempting to deploy a commit to the rayunishinedev's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debounce flush does not cancel the delayed invocation

1 participant