Can I change concurrency at runtime?
Falld0wn18 opened this issue ยท 4 comments
Hello, @timdp .
I found pool.concurrency(Number) on history issue.
So I try to change the value of concurrency in different places, but did not run as expected.
This is my code:
let count = 0;
let pool = null;
let PromiseProducer = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
++count;
// pool.concurrency(3); // run(1,2,3) and code exit
// pool.concurrency(1); // run(1,2) and code exit
return resolve(count);
}, 1000);
});
};
pool = new PromisePool(PromiseProducer, 2);
pool.addEventListener('fulfilled', (event) => {
console.log('Fulfilled', event.data.result);
// pool.concurrency(3); // run(1,2,3,4) after throw error and exit
});
// pool.concurrency(3); // only change before start()
pool.start().then(() => { }).catch((err) => { console.log(err); });
Can I change concurrency after start and run forever ?
Waiting for your reply, thanks!๐
From the output of your code, this indeed looks like a bug. I'll take a closer look. Thanks for reporting!
Could you try this: on line 198 of es6-promise-pool.js, change
var result = nullto
var result = { done: false }This seems to fix it on my end. I'm still working on a test so I'm going to hold off on releasing a new version, but it'd be great if you could already try it and let me know if it helps. ๐
It seems to work fine. Thanks for fix!
If there are other questions, I will give you feedback again.๐
Fix released as of v2.5.0. Thanks!