Lodash debounce cancellation behavior during active trailing edge timers
0 reputation · 14 Jan 2020, 13:02 UTC
Execution Control in Lodash 4.x
The _.debounce function provides a .cancel() method to abort pending executions. When configured with trailing: true, the wrapper maintains a timer to ensure the final call in a sequence is executed after the wait period.
Cancellation Constraints
There is a design uncertainty regarding the state of the internal timer when .cancel() is invoked. Specifically, it is unclear if the cancellation mechanism provides a way to determine if a trailing edge execution was actually pending or if the timer was already idle at the moment of the call.
In high-frequency event environments, relying solely on .cancel() without a maxWait configuration can lead to execution starvation, yet the current API does not return a boolean or status indicator upon cancellation.
- Does
.cancel()explicitly reset the internal state to prevent any subsequent trailing calls from the previous sequence? - Is there a documented method to verify if a debounced function was actively waiting to execute before the cancellation occurred?