Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I change concurrency at runtime? #39

Closed
Falld0wn18 opened this issue Aug 17, 2017 · 4 comments
Closed

Can I change concurrency at runtime? #39

Falld0wn18 opened this issue Aug 17, 2017 · 4 comments

Comments

@Falld0wn18
Copy link

Falld0wn18 commented Aug 17, 2017

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!😃

@timdp
Copy link
Owner

timdp commented Aug 18, 2017

From the output of your code, this indeed looks like a bug. I'll take a closer look. Thanks for reporting!

@timdp
Copy link
Owner

timdp commented Aug 18, 2017

Could you try this: on line 198 of es6-promise-pool.js, change

var result = null

to

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. 🙂

@Falld0wn18
Copy link
Author

It seems to work fine. Thanks for fix!
If there are other questions, I will give you feedback again.😄

@timdp
Copy link
Owner

timdp commented Aug 19, 2017

Fix released as of v2.5.0. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants