Skip to content
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

Why is the abort method on the throttledFn instead of the throttle fun #50

Open
andrscyv opened this issue Apr 9, 2024 · 1 comment

Comments

@andrscyv
Copy link

andrscyv commented Apr 9, 2024

It is confusing if throttledFn.abort() stops all pending calls to execute since it is a method on a single throttledFn.

I'm trying to schedule a bunch of http calls in an array and then calling Promise.all :

const throttle = pThrottle(...);
cons arr = [1,2,3];
const promises = arr.map( num => throttle(makeHttpReq(num)) );
try {
 await Promise.all(promises)
} catch (e) {
 promises[0].abort() // seems weird that I need a throttleFn to achieve this
}

Maybe I'm trying to use this lib for something it wasn't meant to do ?

@sindresorhus
Copy link
Owner

I agree, that's weird. Not sure how I missed that when it was initially added.

The way forward is to move to AbortController instead though: #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants