Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nx.utils

nx.utils.debounce(fn, ms)

nx.utils.debounce(fn, ms): wrap fn into a trailing-edge debounce over nx.timer — the returned value runs fn once, ms after the LAST call, so a burst of rapid calls collapses to a single invocation with the most recent arguments. A timing/control-flow helper (which-key’s show-delay, on-change handlers, resize / scroll reactions); it runs nothing on the input path.

It is callback-shaped, NOT promise-shaped: debounce coalesces a stream of many calls, whereas a promise models one eventual value — different jobs. They compose, though: pass an nx.async function as fn to kick awaitable work after the quiet period, and reach for nx.promise.delay when you want an await-able one-shot sleep instead.

The result is callable AND carries:
cancel() drop a pending invocation (the next call re-arms)
flush() run a pending invocation now (no-op when idle) Each call (re)arms the timer; nothing fires until the calls stop for ms.

Defined in utils.lua.