-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: Move settle functions to own module & add timing methods
- Loading branch information
Showing
14 changed files
with
167 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
var series = require('./series'); | ||
var parallel = require('./parallel'); | ||
var settleSeries = require('./settleSeries'); | ||
var settleParallel = require('./settleParallel'); | ||
'use strict'; | ||
|
||
var asyncDone = require('async-done'); | ||
|
||
var createSeries = require('./lib/createSeries'); | ||
var createParallel = require('./lib/createParallel'); | ||
|
||
module.exports = { | ||
series: series, | ||
parallel: parallel, | ||
settleSeries: settleSeries, | ||
settleParallel: settleParallel, | ||
series: createSeries(asyncDone), | ||
parallel: createParallel(asyncDone) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var async = require('async'); | ||
|
||
function createSeries(mapFn){ | ||
|
||
function buildParallel(){ | ||
var args = _.flatten(arguments); | ||
|
||
function parallel(done){ | ||
async.map(args, mapFn, done); | ||
} | ||
|
||
return parallel; | ||
} | ||
|
||
return buildParallel; | ||
} | ||
|
||
module.exports = createSeries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var async = require('async'); | ||
|
||
function createSeries(mapFn, onDone){ | ||
|
||
function buildSeries(){ | ||
var args = _.flatten(arguments); | ||
|
||
function series(done){ | ||
async.mapSeries(args, mapFn, done); | ||
} | ||
|
||
return series; | ||
} | ||
|
||
return buildSeries; | ||
} | ||
|
||
module.exports = createSeries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var series = require('./settle/series'); | ||
var parallel = require('./settle/parallel'); | ||
|
||
module.exports = { | ||
series: series, | ||
parallel: parallel | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
|
||
var bach = require('../time'); | ||
|
||
function fn1(done){ | ||
done(null, 1); | ||
} | ||
|
||
function fn2(done){ | ||
setTimeout(function(){ | ||
done(null, 2); | ||
}, 500); | ||
} | ||
|
||
function fn3(done){ | ||
done(null, 3); | ||
} | ||
|
||
function done(){} | ||
|
||
test('should emit start event for each function', function(t){ | ||
t.plan(3); | ||
|
||
bach.on('start', function(evt){ | ||
t.ok(evt, 'start event should be defined'); | ||
}); | ||
|
||
bach.parallel(fn1, fn2, fn3)(console.log); | ||
}); | ||
|
||
test('should emit stop event for each function', function(t){ | ||
t.plan(3); | ||
|
||
bach.on('stop', function(evt){ | ||
t.ok(evt, 'stop event should be defined'); | ||
}); | ||
|
||
bach.parallel(fn1, fn2, fn3)(done); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
|
||
var bach = require('../time'); | ||
|
||
function fn1(done){ | ||
done(null, 1); | ||
} | ||
|
||
function fn2(done){ | ||
setTimeout(function(){ | ||
done(null, 2); | ||
}, 500); | ||
} | ||
|
||
function fn3(done){ | ||
done(null, 3); | ||
} | ||
|
||
function done(){} | ||
|
||
test('should emit start event for each function', function(t){ | ||
t.plan(3); | ||
|
||
bach.on('start', function(evt){ | ||
t.ok(evt, 'start event should be defined'); | ||
}); | ||
|
||
bach.series(fn1, fn2, fn3)(console.log); | ||
}); | ||
|
||
test('should emit stop event for each function', function(t){ | ||
t.plan(3); | ||
|
||
bach.on('stop', function(evt){ | ||
t.ok(evt, 'stop event should be defined'); | ||
}); | ||
|
||
bach.series(fn1, fn2, fn3)(done); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var EE = require('events').EventEmitter; | ||
|
||
var bus = new EE(); | ||
|
||
var asyncTime = require('async-time')(bus); | ||
|
||
var createSeries = require('./lib/createSeries'); | ||
var createParallel = require('./lib/createParallel'); | ||
|
||
bus.series = createSeries(asyncTime); | ||
bus.parallel = createParallel(asyncTime); | ||
|
||
module.exports = bus; |