Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/async/compose.js
1126 views
1
'use strict';
2
3
Object.defineProperty(exports, "__esModule", {
4
value: true
5
});
6
exports.default = compose;
7
8
var _seq = require('./seq.js');
9
10
var _seq2 = _interopRequireDefault(_seq);
11
12
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14
/**
15
* Creates a function which is a composition of the passed asynchronous
16
* functions. Each function consumes the return value of the function that
17
* follows. Composing functions `f()`, `g()`, and `h()` would produce the result
18
* of `f(g(h()))`, only this version uses callbacks to obtain the return values.
19
*
20
* If the last argument to the composed function is not a function, a promise
21
* is returned when you call it.
22
*
23
* Each function is executed with the `this` binding of the composed function.
24
*
25
* @name compose
26
* @static
27
* @memberOf module:ControlFlow
28
* @method
29
* @category Control Flow
30
* @param {...AsyncFunction} functions - the asynchronous functions to compose
31
* @returns {Function} an asynchronous function that is the composed
32
* asynchronous `functions`
33
* @example
34
*
35
* function add1(n, callback) {
36
* setTimeout(function () {
37
* callback(null, n + 1);
38
* }, 10);
39
* }
40
*
41
* function mul3(n, callback) {
42
* setTimeout(function () {
43
* callback(null, n * 3);
44
* }, 10);
45
* }
46
*
47
* var add1mul3 = async.compose(mul3, add1);
48
* add1mul3(4, function (err, result) {
49
* // result now equals 15
50
* });
51
*/
52
function compose(...args) {
53
return (0, _seq2.default)(...args.reverse());
54
}
55
module.exports = exports['default'];
56