3 Object.defineProperty(exports, "__esModule", {
7 var _noop = require('lodash/noop');
9 var _noop2 = _interopRequireDefault(_noop);
11 var _rest = require('./internal/rest');
13 var _rest2 = _interopRequireDefault(_rest);
15 var _reduce = require('./reduce');
17 var _reduce2 = _interopRequireDefault(_reduce);
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22 * Version of the compose function that is more natural to read. Each function
23 * consumes the return value of the previous function. It is the equivalent of
24 * [compose]{@link module:ControlFlow.compose} with the arguments reversed.
26 * Each function is executed with the `this` binding of the composed function.
30 * @memberOf module:ControlFlow
32 * @see [async.compose]{@link module:ControlFlow.compose}
33 * @category Control Flow
34 * @param {...Function} functions - the asynchronous functions to compose
35 * @returns {Function} a function that composes the `functions` in order
38 * // Requires lodash (or underscore), express3 and dresende's orm2.
39 * // Part of an app, that fetches cats of the logged user.
40 * // This example uses `seq` function to avoid overnesting and error
41 * // handling clutter.
42 * app.get('/cats', function(request, response) {
43 * var User = request.models.User;
45 * _.bind(User.get, User), // 'User.get' has signature (id, callback(err, data))
46 * function(user, fn) {
47 * user.getCats(fn); // 'getCats' has signature (callback(err, data))
49 * )(req.session.user_id, function (err, cats) {
52 * response.json({ status: 'error', message: err.message });
54 * response.json({ status: 'ok', message: 'Cats found', data: cats });
59 exports.default = (0, _rest2.default)(function seq(functions) {
60 return (0, _rest2.default)(function (args) {
63 var cb = args[args.length - 1];
64 if (typeof cb == 'function') {
70 (0, _reduce2.default)(functions, args, function (newargs, fn, cb) {
71 fn.apply(that, newargs.concat((0, _rest2.default)(function (err, nextargs) {
74 }, function (err, results) {
75 cb.apply(that, [err].concat(results));
79 module.exports = exports['default'];