sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
2.06k stars 106 forks source link

Add support for clearing the queue #20

Closed callmehiphop closed 4 years ago

callmehiphop commented 4 years ago

Closes #18

Issue had been sitting for a little bit, so I decided to try my hand at it. Sorry in advance for any glaring mistakes!

sindresorhus commented 4 years ago

Bump :)

shirshak55 commented 4 years ago

hmm do clearing queue means settings current queue length to 0 sufficient only?

callmehiphop commented 4 years ago

@shirshak55 it's a personal preference for emptying arrays, allows us to re-use the same array without increasing the time complexity (I think).

shirshak55 commented 4 years ago

@callmehiphop yea I think it is correct and best option here. Was just worried like lets say there are 2 promise and are running and we reset the queue but those promises would still be running and user may think pending count is 0 meaning javascript is doing nothing (But in reality its still running those promises.) . Yea I don't think there is easy way to cancel running promise :(

callmehiphop commented 4 years ago

@shirshak55 oh! That isn't really what the scope of this PR covers. This only clears the queue of functions waiting to be called, once they're executed there is no stopping them. You might be able to do something clever using a cancelable promise though.

sindresorhus commented 4 years ago

The TS file should be in sync with the readme documentation-wise.

callmehiphop commented 4 years ago

@sindresorhus ah right, sorry about that! I think we should be good to go now 🤞