Source

async/pipeAsync.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Usage:
 * ```
 * const asyncFunctions: (() => void)[] = Array(6)
 *  .map((v, i) => (input: string) => new Promise(resolve => {
 *    setTimeout(() => {
 *      const nextInput = `${input}-${i}`
 *      console.log('Resolve', i, input, nextInput)
 *      resolve(nextInput)
 *    }, 1000)
 *  }))
 * pipeAsync(...asyncFunctions)('Input to the first function')
 * ```
 * @category async
 * @module pipeAsync
 */
var pipeAsync = function () {
    var functions = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        functions[_i] = arguments[_i];
    }
    return function (input) { return functions
        .reduce(function (chain, func) { return chain.then(func); }, Promise.resolve(input)); };
};
exports.default = pipeAsync;