blob: c9e02c18a265857966eb70f1706299816917075d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
'use strict';
import noop from 'lodash-es/noop';
import rest from 'lodash-es/rest';
import reduce from './reduce';
export default function seq( /* functions... */ ) {
var fns = arguments;
return rest(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([rest(function(err, nextargs) {
cb(err, nextargs);
})]));
},
function(err, results) {
cb.apply(that, [err].concat(results));
});
});
}
|