diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-12-23 15:50:39 -0500 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-12-29 16:48:48 -0500 |
commit | 18e61d4f07f48604601f2effdbe2a7e188d14d4a (patch) | |
tree | d4761428f57ec80816bea109124fd836cdaf20a6 /lib/seq.js | |
parent | 7127b67f94a22247c36bf40e4f2685912e0f80e9 (diff) | |
download | async-18e61d4f07f48604601f2effdbe2a7e188d14d4a.tar.gz |
[WIP] modularization (#984)
Diffstat (limited to 'lib/seq.js')
-rw-r--r-- | lib/seq.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/seq.js b/lib/seq.js new file mode 100644 index 0000000..184dc4b --- /dev/null +++ b/lib/seq.js @@ -0,0 +1,26 @@ +import noop from 'lodash/utility/noop'; +import reduce from './reduce'; +import restParam from 'lodash/function/restParam'; + +export default function seq( /* functions... */ ) { + var fns = arguments; + return restParam(function(args) { + var that = this; + + var cb = args[args.length - 1]; + if (typeof cb == 'function') { + args.pop(); + } else { + cb = noop; + } + + reduce(fns, args, function(newargs, fn, cb) { + fn.apply(that, newargs.concat([restParam(function(err, nextargs) { + cb(err, nextargs); + })])); + }, + function(err, results) { + cb.apply(that, [err].concat(results)); + }); + }); +} |