Skip to content

Commit

Permalink
Breaking: Remove timing methods & switch to now-and-later for series/…
Browse files Browse the repository at this point in the history
…parallel
  • Loading branch information
phated committed Jun 27, 2016
1 parent 90371d5 commit 54b0a6e
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 124 deletions.
9 changes: 2 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use strict';

var asyncDone = require('async-done');

var createSeries = require('./lib/createSeries');
var createParallel = require('./lib/createParallel');

module.exports = {
series: createSeries(asyncDone),
parallel: createParallel(asyncDone)
series: require('./lib/series'),
parallel: require('./lib/parallel')
};
24 changes: 24 additions & 0 deletions lib/parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

var _ = require('lodash');
var asyncDone = require('async-done');
var nowAndLater = require('now-and-later');

var verifyArguments = require('./verifyArguments');

function buildParallel(){
var args = verifyArguments(arguments);

var extensions = {};
if(typeof _.last(args) !== 'function'){
extensions = _.last(args);
}

function parallel(done){
nowAndLater.parallel(args, asyncDone, extensions, done);
}

return parallel;
}

module.exports = buildParallel;
24 changes: 24 additions & 0 deletions lib/series.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

var _ = require('lodash');
var asyncDone = require('async-done');
var nowAndLater = require('now-and-later');

var verifyArguments = require('./verifyArguments');

function buildSeries(){
var args = verifyArguments(arguments);

var extensions = {};
if(typeof _.last(args) !== 'function'){
extensions = _.last(args);
}

function series(done){
nowAndLater.series(args, asyncDone, extensions, done);
}

return series;
}

module.exports = buildSeries;
24 changes: 18 additions & 6 deletions lib/verifyArguments.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
'use strict';

var assert = require('assert');

module.exports = function(args){
var _ = require('lodash');

function verifyArguments(args){
args = _.flatten(args);

assert(args.length > 0, 'A set of functions to combine is mandatory');
assert.ok(args.length, 'A set of functions to combine is required');

args.forEach(function(arg, argIdx){
assert.equal(typeof arg, 'function',
'Only functions can be combined, got ' + typeof arg + ' for argument ' + argIdx);
_.forEach(args, function(arg, argIdx){
var isFunction = _.isFunction(arg);
if(isFunction){
return;
}

var msg = 'Only functions can be combined, got ' + typeof arg + ' for argument ' + argIdx;
assert.ok(isFunction, msg);
});

return args;
};
}

module.exports = verifyArguments;
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
"tap": "~0.4.8"
},
"dependencies": {
"async": "~0.2.10",
"async-done": "~0.3.0",
"async-settle": "~0.1.0",
"async-time": "~0.0.1",
"lodash": "~2.4.1"
"lodash": "~2.4.1",
"now-and-later": "0.0.2"
}
}
2 changes: 1 addition & 1 deletion test/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test('should execute functions in parallel and call callback with error on an er
bach.parallel(fn1, slowFn, fn3, fnError)(function(error, results){
t.ok(error, 'error should be defined');
t.ok(results, 'results should be defined');
t.deepEqual(results, [1, , 3, undefined], 'results should be [1, , 3, undefined]');
t.deepEqual(results, [1, undefined, 3, undefined], 'results should be [1, undefined, 3, undefined]');
t.ok(error instanceof Error, 'error should be instance of an Error');
t.end();
});
Expand Down
49 changes: 0 additions & 49 deletions test/timeParallel.js

This file was deleted.

41 changes: 0 additions & 41 deletions test/timeSeries.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/verifyArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('should throw descriptive error message on when no arguments provided', fun
t.throws(function(){
verifyArguments([]);
}, {
name: 'AssertionError', message: 'A set of functions to combine is mandatory'
name: 'AssertionError', message: 'A set of functions to combine is required'
}, 'should throw AssertionError');
t.end();
});
});
15 changes: 0 additions & 15 deletions time.js

This file was deleted.

0 comments on commit 54b0a6e

Please sign in to comment.