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

When a number is passed as concurrent parameter, execute the tasks in… #56

Merged
merged 5 commits into from
Apr 28, 2017

Conversation

alexpsi
Copy link
Contributor

@alexpsi alexpsi commented Feb 26, 2017

… a chunked parallel manner.

@alexpsi alexpsi mentioned this pull request Feb 26, 2017
@alexpsi
Copy link
Contributor Author

alexpsi commented Mar 20, 2017

Hi, is there anything wrong with the PR?

@SamVerschueren
Copy link
Owner

Hi @alexpsi. No sorry, didn't find the time to look into it yet. Will try to have a look this week, quite busy lately.

@alexpsi
Copy link
Contributor Author

alexpsi commented Mar 20, 2017

Thanks, no need to hurry :)
Great library btw!

@petemill petemill mentioned this pull request Apr 4, 2017
@steelbrain
Copy link

Any update on this? I have to reimplement a lot of code here in several places. Would be nice to have this implemented in the core

index.js Outdated
this._checkAll(context);
return runTask(task, context, errors);
}));
}), Promise.resolve());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth using something like p-map to simplify the code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yap, did not know of p-map, i will try it out.

@alexpsi
Copy link
Contributor Author

alexpsi commented Apr 26, 2017

@sindresorhus @SamVerschueren I refactored it with p-map, nice thing is that it does not have to wait for the chunk to finish anymore, so it is even better

index.js Outdated
tasks = pMap(this._tasks, task => {
this._checkAll(context);
return runTask(task, context, errors);
}, {concurrency: this._options.concurrent});
} else {
tasks = this._tasks.reduce((promise, task) => promise.then(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, we could just set {concurrency: 1} in the above implementation. p-map would then run in serial.

index.js Outdated
@@ -82,6 +83,11 @@ class Listr {
let tasks;
if (this._options.concurrent === true) {
tasks = Promise.all(this._tasks.map(task => runTask(task, context, errors)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this could just use the pMap() method with concurrency Infinity.

index.js Outdated
@@ -82,6 +83,11 @@ class Listr {
let tasks;
if (this._options.concurrent === true) {
tasks = Promise.all(this._tasks.map(task => runTask(task, context, errors)));
} else if (typeof this._options.concurrent === 'number' && this._options.concurrent > 0) {
tasks = pMap(this._tasks, task => {
this._checkAll(context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this called here, but not when this._options.concurrent === true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus Ahhh sorry, last commit was a bad paste. Next one sets it straight... :)

Copy link
Owner

@SamVerschueren SamVerschueren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, this is pretty clean with p-map (thanks @sindresorhus :)). And thank you for the PR! Sorry for the late reply though.

Could you also change the docs for the concurrent option?

index.js Outdated
if (this._options.concurrent === true) {
tasks = Promise.all(this._tasks.map(task => runTask(task, context, errors)));
let concurrency;
if (!this._options.concurrent) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it the other way around

if (this._options.concurrent === true) {
    concurrency = Infinity;
} else if (...) {

} else {
    concurrency = 1;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wondering, wouldn't it be cleaner if we did all of this in the constructor instead? And thus set this._options.concurrent to the correct value for p-map.

index.js Outdated

return runTask(task, context, errors);
}), Promise.resolve());
concurrency = 'Infinity';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infinity, not 'Infinity' :)

renderer: SimpleRenderer,
concurrent: 2
});
testOutput(t, [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line

'P4 [completed]',
'done'
]);
await list.run();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line

index.js Outdated
} else if (typeof this._options.concurrent === 'number') {
this.concurrency = this._options.concurrent;
} else {
this.concurrency = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set this.concurrency = 1 at line 35 and remove this one

Copy link
Owner

@SamVerschueren SamVerschueren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, think this is the last one

readme.md Outdated
Default: `false`

Set to `true` if you want tasks to run concurrently.
Set to `true` if you want to run tasks in parallel, set to a number to control
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darn, missed this one :).

Set to true if you want to run the tasks in parallel. Set to a number to control the concurrency.

One line, no breaks.

@SamVerschueren SamVerschueren merged commit f4f8f1d into SamVerschueren:master Apr 28, 2017
@alexpsi
Copy link
Contributor Author

alexpsi commented Apr 28, 2017

@SamVerschueren Thanks!!!

@SamVerschueren
Copy link
Owner

Thank you for all the work (and for your patience). Releasing it as we speak (0.12.0)

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

Successfully merging this pull request may close these issues.

4 participants