summaryrefslogtreecommitdiff
path: root/lib/seq.js
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2015-12-23 15:50:39 -0500
committerGraeme Yeates <yeatesgraeme@gmail.com>2015-12-29 16:48:48 -0500
commit18e61d4f07f48604601f2effdbe2a7e188d14d4a (patch)
treed4761428f57ec80816bea109124fd836cdaf20a6 /lib/seq.js
parent7127b67f94a22247c36bf40e4f2685912e0f80e9 (diff)
downloadasync-18e61d4f07f48604601f2effdbe2a7e188d14d4a.tar.gz
[WIP] modularization (#984)
Diffstat (limited to 'lib/seq.js')
-rw-r--r--lib/seq.js26
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));
+ });
+ });
+}