Skip to content

Commit

Permalink
only trigger task completion async if explicitly requested
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Kellen committed Mar 12, 2014
1 parent 8bbc8ac commit a76e817
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.4.4:
date: 2014-04-12
changes:
- Only signal completion of tasks async if grunt.task.start is invoked with `{asyncDone:true}`.
v0.4.3:
date: 2014-03-07
changes:
Expand Down
4 changes: 3 additions & 1 deletion lib/grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,7 @@ grunt.tasks = function(tasks, options, done) {
// Execute all tasks, in order. Passing each task individually in a forEach
// allows the error callback to execute multiple times.
tasks.forEach(function(name) { task.run(name); });
task.start();
// Run tasks async internally to reduce call-stack, per:
// https://github.com/gruntjs/grunt/pull/1026
task.start({asyncDone:true});
};
19 changes: 14 additions & 5 deletions lib/util/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
};

// Run a task function, handling this.async / return value.
Task.prototype.runTaskFn = function(context, fn, done) {
Task.prototype.runTaskFn = function(context, fn, done, asyncDone) {
// Async flag.
var async = false;

Expand All @@ -215,9 +215,15 @@
if (!success && this._options.error) {
this._options.error.call({name: context.name, nameArgs: context.nameArgs}, err);
}
process.nextTick(function () {
// only call done async if explicitly requested to
// see: https://github.com/gruntjs/grunt/pull/1026
if (asyncDone) {
process.nextTick(function () {
done(err, success);
});
} else {
done(err, success);
});
}
}.bind(this);

// When called, sets the async flag and returns a function that can
Expand Down Expand Up @@ -248,7 +254,10 @@
};

// Begin task queue processing. Ie. run all tasks.
Task.prototype.start = function() {
Task.prototype.start = function(opts) {
if (!opts) {
opts = {};
}
// Abort if already running.
if (this._running) { return false; }
// Actually process the next task.
Expand Down Expand Up @@ -285,7 +294,7 @@
// Actually run the task function (handling this.async, etc)
this.runTaskFn(context, function() {
return thing.task.fn.apply(this, this.args);
}, nextTask);
}, nextTask, !!opts.asyncDone);

}.bind(this);

Expand Down

0 comments on commit a76e817

Please sign in to comment.