es-toolkit icon indicating copy to clipboard operation
es-toolkit copied to clipboard

feat(throttle): add promise based feature

Open dayongkr opened this issue 1 year ago • 2 comments

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 throttleMs parameter 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.

dayongkr avatar Aug 22 '24 03:08 dayongkr

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

vercel[bot] avatar Aug 22 '24 03:08 vercel[bot]

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

Impacted file tree graph

@@           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           

codecov-commenter avatar Aug 22 '24 03:08 codecov-commenter

I am not really sure if we add this feature to throttle. However, we might add this called throttleAsync as an async library.

raon0211 avatar Aug 22 '24 14:08 raon0211

I am not really sure if we add this feature to throttle. However, we might add this called throttleAsync as an async library.

I agree with adding a method called throttleAsync. I will reopen the issue for further discussion.

dayongkr avatar Aug 22 '24 14:08 dayongkr