DEV Community

Discussion on: Introducing the Async Debounce pattern

Collapse
 
xowap profile image
Rémy 🤖

Thanks for the feedback!

If I understand your post correctly, I think it's what the lib actually does under the hood. You can look at the diagram, there is actually 3 entry points (in green) depending on the current state

  • When inactive, go to waiting then run the request
  • When waiting, replace the params and keep waiting (don't reset the timer)
  • When running, wait for the run to finish and run with the new params

Calls are not stacked, so only the latest call is taken in account. Since you can't cancel Promises (yet?) though you indeed have to wait for the previous call to finish before running a new one.

Is that clearer? Or am I mistaken?