Problem Statement
Some scenarios require guaranteed execution of the most recent call, even if it occurs during a throttle window. Implement a trailing-edge throttle that captures and executes the last call after the wait period.
Requirements
Implement a throttleTrailing(func, wait) function that:
- Does NOT execute immediately on the first call
- Queues the most recent call during the wait period
- Executes the queued call at the end of each wait period
- If no calls occur during a wait period, nothing executes
Example Usage
Visual Timeline
Use Cases
- Syncing final position after drag operations
- Ensuring the last form state is saved
- Analytics that need the final interaction state
Follow-up Questions
- How would you handle arguments for the trailing call?
- What happens if the user stops interacting mid-window?