util: implement debounce - #65899
Conversation
I found myself using debounce quite a bit recently while testing some recent other additions (quic and dtls testing, perf_hooks improvements, etc). I was using an npm dependency right up until I realized just how generally useful it is to actually have it Just There. So, since it was a holiday and I just felt like it... util.debounce(...) Signed-off-by: James M Snell <jasnell@gmail.com>
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65899 +/- ##
========================================
Coverage 90.17% 90.17%
========================================
Files 771 772 +1
Lines 265097 265291 +194
Branches 50355 50393 +38
========================================
+ Hits 239040 239234 +194
- Misses 17009 17016 +7
+ Partials 9048 9041 -7
π New features to boost your workflow:
|
|
what's the userland precedent for an AbortSignal-aware debounce implementation? |
|
hm, neither very widely used, but at least it's nonzero. i've never seen that usage before, personally. |
|
If you're gonna have options anyway, you might consider having an option for a call that happens at least |
|
The use of AbortSignal here is a bit weird, and in my opinion wrong. AbortSignals can only transition from "not aborted" -> "aborted" once, whereas the expectation is that a function like this will be called many times. You can technically dispatch |
I found myself using debounce quite a bit recently while testing some recent other additions (quic and dtls testing, perf_hooks improvements, etc). I was using an npm dependency right up until I realized just how generally useful it is to actually have it Just There. So, since it was a holiday and I just felt like it... util.debounce(...)