es-toolkit
es-toolkit copied to clipboard
feat(throttle): add promise based feature
Description
At now, es-toolkit/throttle has only a time based feature.
But if we also support promise based feature, we can do this:
const throttledFetch = throttle(fetch);
throttledFetch('https://es.toolkit/api/login') // Start the first fetching
throttledFetch('https://es.toolkit/api/login') // Ignored
// End the first fetching
throttledFetch('https://es.toolkit/api/login') // Start the second fetching
// End the second fetching
Currently, if the
throttleMsparameter is not provided, then It works promise based.
I think that this feature is also good for preventing double(or nth)-clicked.
I'm not sure this feature is good for es-toolkit, so I stop working. But this approach is acceptable, then I am going to improve interface and change docs.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| es-toolkit | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Aug 22, 2024 4:25am |
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 99.77%. Comparing base (
5c551b8) to head (db336da).
Additional details and impacted files
@@ Coverage Diff @@
## main #414 +/- ##
=======================================
Coverage 99.77% 99.77%
=======================================
Files 161 161
Lines 1323 1330 +7
Branches 358 361 +3
=======================================
+ Hits 1320 1327 +7
Misses 2 2
Partials 1 1
I am not really sure if we add this feature to throttle. However, we might add this called throttleAsync as an async library.
I am not really sure if we add this feature to throttle. However, we might add this called
throttleAsyncas an async library.
I agree with adding a method called throttleAsync. I will reopen the issue for further discussion.