import debounce from '@pim.sk/utils/debounce.mjs'
Delays function execution. Each call resets the timer — fn runs only after the last call + wait ms.
fn = () => { ... }
const db = debounce(fn, 800) // fn = user function, wait = 800ms
db.start() // resets timer on each call
db.start() // only this last call fires fn
Cancels any pending debounce and executes fn immediately (no delay).
db.start() // pending...
db.run() // fires NOW, cancels pending
db.start() // starts 800ms timer
db.run() // cancels timer, runs fn immediately
Cancels a pending debounce — fn will NOT be called.
db.start() // pending...
db.stop() // cancelled
db.start() // starts 800ms timer
db.stop() // cancels — fn never fires
Returns true when debounce is not active (no pending timer, fn already executed or stopped).
db.isEnd() → true | false
db.start()
db.isEnd() // false — timer still running
// after 800ms...
db.isEnd() // true — fn already executed
Async callback — waits until debounce finishes (fn executed), then runs the callback.
db.start()
db.onEnd( () => { ... } )
const db = debounce(fn, 500)
db.start()
db.onEnd(() => {
// runs after fn completes
})