Skip to content

Commit

Permalink
add support for settling functions - ref gulpjs/gulp#871
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 14, 2015
1 parent 44d8afe commit 84dd7aa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function Undertaker(Registry){

this._registry = new Registry();

this._settle = (process.argv.indexOf('--undertaker-settle') !== -1);

validateRegistry(this._registry);

this._lastRuns = {};
Expand Down
5 changes: 4 additions & 1 deletion lib/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ var createExtensions = require('./helpers/createExtensions');

function parallel(){
/* jshint validthis: true */

var create = this._settle ? bach.settleParallel : bach.parallel;

var args = normalizeArgs(this._registry, arguments);
var extensions = createExtensions(this);
var fn = bach.parallel(args, extensions);
var fn = create(args, extensions);
metadata.set(fn, {
name: 'parallel',
tree: {
Expand Down
5 changes: 4 additions & 1 deletion lib/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ var createExtensions = require('./helpers/createExtensions');

function series(){
/* jshint validthis: true */

var create = this._settle ? bach.settleSeries : bach.series;

var args = normalizeArgs(this._registry, arguments);
var extensions = createExtensions(this);
var fn = bach.series(args, extensions);
var fn = create(args, extensions);
metadata.set(fn, {
name: 'series',
tree: {
Expand Down
2 changes: 1 addition & 1 deletion test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('integrations', function() {
var count = 0;

taker.task('clean', aOnce(function(cb) {
console.log(cb());
cb();
count++;
del(['./fixtures/some-build.txt'], {cwd: __dirname}, cb);
}));
Expand Down
9 changes: 9 additions & 0 deletions test/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ describe('parallel', function(){
expect(unregistered).to.throw('Task never defined: unregistered');
done();
});

it('should process all functions if settle flag is true', function(done){
taker._settle = true;
taker.parallel('test1', 'error', 'test3')(function(err, results){
expect(err[0]).to.be.an.instanceof(Error);
expect(results).to.deep.equal([1, 3]);
done();
});
});
});
9 changes: 9 additions & 0 deletions test/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ describe('series', function(){
expect(unregistered).to.throw('Task never defined: unregistered');
done();
});

it('should process all functions if settle flag is true', function(done){
taker._settle = true;
taker.series('test1', 'error', 'test3')(function(err, results){
expect(err[0]).to.be.an.instanceof(Error);
expect(results).to.deep.equal([1, 3]);
done();
});
});
});

0 comments on commit 84dd7aa

Please sign in to comment.