Comments (4)
Hi, thanks for your suggestion!
I’ve thought about adding a cancel
feature to throttle
, but the way throttle
works makes it tricky. Since throttle
doesn't actually queue any asynchronous tasks, it’s hard to define what exactly would be canceled. That’s why we haven’t included a cancel
option in throttle
.
What are your thoughts?
from es-toolkit.
I simply thought that the cancel
feature would cancel the pending function and make it immediately callable by setting lastCallTime to null. For example, it should be able to pass the following test code.
it('should call the function immediately after cancel is called', async () => {
const func = vi.fn();
const throttledFunc = throttle(func, 100);
throttledFunc();
expect(func).toHaveBeenCalledTimes(1);
throttledFunc.cancel();
throttledFunc();
expect(func).toHaveBeenCalledTimes(2);
});
How do you feel about providing this kind of cancel
?
from es-toolkit.
As you mentioned, providing those kinds of cancel
options might be helpful.
However, I'm not sure if it is really that beneficial. For debounce
, we have to cancel the debounced function when the component is cleaned up, but for throttle
, there's no need to do so.
Additionally, since we can only abort AbortController
s once, it might not align well with the definition of cancel
for throttle
.
So, because it is not a major use case, I think we might not support cancel
for throttle
in es-toolkit
. What do you think?
from es-toolkit.
Yes, I agree that it is not a major use case. I'll close this issue. Thank you for opinion 🙇🏻♀️
from es-toolkit.
Related Issues (20)
- Enhancing `toFilled` Function to Support as const HOT 1
- orderBy keys don't support nested keys HOT 2
- throttle support leading and trailing HOT 1
- Support for `padEnd`
- Support for `forEach` HOT 1
- cloneDeep is not an export of es-toolkit HOT 3
- Check all files in ci, when `.eslintrc.js`, `.prettierrc`, `.prettierignore` files are changed
- Fix all of lint Error
- Add `concat`
- Support for `flatMapDeep` HOT 1
- feature request: how to use shuffle by key HOT 2
- Add a document for migrating from lodash HOT 1
- Inquiry about Supporting Lodash `template` Function in es-toolkit HOT 1
- Mismatch between docs and 1.13.1-latest HOT 3
- Unexpected behavior using orderBy HOT 6
- Suggest to enhance `cloneDeep` with custom clone rules HOT 1
- Add custom order function in `es-toolkit/compat` HOT 4
- toMerge() is not exported
- Support for `findIndex` HOT 2
- Support for `compat/indexOf` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from es-toolkit.