summaryrefslogtreecommitdiff
path: root/node_modules/async/waterfall.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-11-28 17:14:38 +0100
committerMinteck <contact@minteck.org>2022-11-28 17:14:38 +0100
commit18efd30a263ec0d79a26a82cbd8c90c9f81056b7 (patch)
treeaea01bf3506dda706719fc68eb37b77ed9ef3fe8 /node_modules/async/waterfall.js
downloadautoreport-mane.tar.gz
autoreport-mane.tar.bz2
autoreport-mane.zip
Open sourceHEADmane
Diffstat (limited to 'node_modules/async/waterfall.js')
-rw-r--r--node_modules/async/waterfall.js105
1 files changed, 105 insertions, 0 deletions
diff --git a/node_modules/async/waterfall.js b/node_modules/async/waterfall.js
new file mode 100644
index 0000000..fcd0dc1
--- /dev/null
+++ b/node_modules/async/waterfall.js
@@ -0,0 +1,105 @@
+'use strict';
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+
+var _once = require('./internal/once.js');
+
+var _once2 = _interopRequireDefault(_once);
+
+var _onlyOnce = require('./internal/onlyOnce.js');
+
+var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
+
+var _wrapAsync = require('./internal/wrapAsync.js');
+
+var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
+
+var _awaitify = require('./internal/awaitify.js');
+
+var _awaitify2 = _interopRequireDefault(_awaitify);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * Runs the `tasks` array of functions in series, each passing their results to
+ * the next in the array. However, if any of the `tasks` pass an error to their
+ * own callback, the next function is not executed, and the main `callback` is
+ * immediately called with the error.
+ *
+ * @name waterfall
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array} tasks - An array of [async functions]{@link AsyncFunction}
+ * to run.
+ * Each function should complete with any number of `result` values.
+ * The `result` values will be passed as arguments, in order, to the next task.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed. This will be passed the results of the last task's
+ * callback. Invoked with (err, [results]).
+ * @returns {Promise} a promise, if a callback is omitted
+ * @example
+ *
+ * async.waterfall([
+ * function(callback) {
+ * callback(null, 'one', 'two');
+ * },
+ * function(arg1, arg2, callback) {
+ * // arg1 now equals 'one' and arg2 now equals 'two'
+ * callback(null, 'three');
+ * },
+ * function(arg1, callback) {
+ * // arg1 now equals 'three'
+ * callback(null, 'done');
+ * }
+ * ], function (err, result) {
+ * // result now equals 'done'
+ * });
+ *
+ * // Or, with named functions:
+ * async.waterfall([
+ * myFirstFunction,
+ * mySecondFunction,
+ * myLastFunction,
+ * ], function (err, result) {
+ * // result now equals 'done'
+ * });
+ * function myFirstFunction(callback) {
+ * callback(null, 'one', 'two');
+ * }
+ * function mySecondFunction(arg1, arg2, callback) {
+ * // arg1 now equals 'one' and arg2 now equals 'two'
+ * callback(null, 'three');
+ * }
+ * function myLastFunction(arg1, callback) {
+ * // arg1 now equals 'three'
+ * callback(null, 'done');
+ * }
+ */
+function waterfall(tasks, callback) {
+ callback = (0, _once2.default)(callback);
+ if (!Array.isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
+ if (!tasks.length) return callback();
+ var taskIndex = 0;
+
+ function nextTask(args) {
+ var task = (0, _wrapAsync2.default)(tasks[taskIndex++]);
+ task(...args, (0, _onlyOnce2.default)(next));
+ }
+
+ function next(err, ...args) {
+ if (err === false) return;
+ if (err || taskIndex === tasks.length) {
+ return callback(err, ...args);
+ }
+ nextTask(args);
+ }
+
+ nextTask([]);
+}
+
+exports.default = (0, _awaitify2.default)(waterfall);
+module.exports = exports['default']; \ No newline at end of file