-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cancel() method #3
Comments
This would be nice. Just wanted to also stop by and say this library works nicely. I like the whole debounce per key thing most 👍 |
thanks :) will look at providing a cancel method |
Any update on this? Would also love a cancel method! |
Hey, I'd like to work on this but I'm not sure what API you have in mind and what usecase. If it's to handle unmounted react components, you can easily handle that directly inside the promise callback Otherwise, it's already possible to "cancel" a promise in userland. I have internal code that do so in the lib that I could expose for conveniency: https://github.com/slorber/awesome-debounce-promise/blob/master/index.js#L12 If that is not enough, please show me your usecase + how you would like that cancellation to work? |
Hi, I've extracted a new package from this lib to easily add promise cancellation to any existing promise. I've not included any "cancel" method directly in this lib because the feature can be plugged in userland and I think it's better to keep the returned value of the async function to have exactly the same type as the original function Maybe if this is not enough I could assign a cancel method to the returned function? But it would have to take a "key" arg so that people using the key feature could cancel the right debounced function |
Will probably try to support this anyway. Will probably implement this first in https://github.com/slorber/awesome-imperative-promise and provide the ability to add resolve/reject/cancel methods directly to an async function, instead of adding those methods only to a promise. If anyone want to give a try, contributions are welcome ;) |
Hey, I've been playing with request abortion recently. It's not yet supported by this library (I'm using TS and it's quite hard to handle the typing but I see how it could be done) In the meantime, if you use React and hooks you can try https://github.com/slorber/react-async-hook which support cancellation, you'll just need to pass an abortSignal as parameter to your async call and it will be called as soon as your react component is not interested anymore by the async call result. |
Are there any examples anywhere with fetch cancellation now? I've looked but can't find any. This is a very common use case, so was surprised. |
Most debounce functions provide a cancel() method.
Use case: https://stackoverflow.com/q/23123138#comment57603349_28046731
The text was updated successfully, but these errors were encountered: