sindresorhus / p-queue

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

Feature request: onSize promise #128

Closed Azmisov closed 2 years ago

Azmisov commented 3 years ago

How about having another onSize(limit) promise, which resolves when size <= limit? You already have onEmpty and onIdle. Personally I don't want to queue 100k+ promises right at the start. So would be nice to be able to queue them on demand when queue size drops below say 2x concurrency.

Could perhaps consider onSizeBy(limit, options) as well.

dobesv commented 3 years ago

This has been added in the latest release.

Richienb commented 2 years ago

For size < limit, use .onSizeLessThan:

await queue.onSizeLessThan(limit)

For size <= limit:

await queue.onSizeLessThan(limit + 1)