sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.45k stars 185 forks source link

Add `.sizeBy()` method to find queue size by priority #94

Closed bobjflong closed 4 years ago

bobjflong commented 4 years ago

Thanks for a great and useful library.

We use p-queue to totally order all of the web requests our app makes. However this means that there is a risk that when the user closes the tab, there is some work left pending in the promise queue.

We use priority to discern between important requests (eg. a user action) and unimportant requests (eg. updating something unimportant in the background).

We use an onbeforeunload hook to warn the user that they could lose changes if queue.size > 0. However it would be an improvement to user experience if we could only warn them if the queue contains very important actions (based on priority). This is what motivated me to implement sizeBy, which takes the same priority options as add, and filters the results.

Interested to hear what you think!

bobjflong commented 4 years ago

I had to set the typescript version in order to get CI to pass. I'm not sure exactly what that issue is, but it's affecting master too as far as I can tell.

sindresorhus commented 4 years ago

And you need to update: https://github.com/sindresorhus/p-queue#custom-queueclass

sindresorhus commented 4 years ago

Thanks :)