Closed andybee closed 2 years ago
Your counter is flawed. You must increase it when the function is actually executed.
import delay from 'delay';
import pLimit from './index.js';
const limit = pLimit(1);
const wasteTime = async (value) => {
await delay(1000);
return value;
};
let count = 0;
setInterval(async () => {
console.log(await limit(() => wasteTime(++count)));
}, 500);
If this is actually an issue with p-limit
, it would be amazing if you would be willing to submit a failing test that shows it.
🤦♂️ Thank you!
I have some code which is firing off promises on an "ad-hoc" basis. I need to limit how many are actually executing at the same time (else too many open network connections, etc.)
Using p-limit it never fires a promise if it comes in whilst all concurrent capacity is in-use.
A quick demo of this issue:
I would expect to see output of:
etc.
But instead I see:
It looks like the functions called when the pool is busy never execute?