mirror of
https://github.com/azure/login.git
synced 2026-06-06 22:47:06 +00:00
* Bump lodash from 4.17.15 to 4.17.19 (#52) Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amruta Kawade <65217380+AmrutaKawade@users.noreply.github.com> * Bump @actions/core from 1.1.3 to 1.2.6 (#60) Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.1.3 to 1.2.6. - [Release notes](https://github.com/actions/toolkit/releases) - [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amruta Kawade <65217380+AmrutaKawade@users.noreply.github.com> * updating node_nodules * updated package-lock Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
93 lines
No EOL
2.8 KiB
JavaScript
93 lines
No EOL
2.8 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports["default"] = connect;
|
|
|
|
/**
|
|
* Run composed `tasks` callback functions in series.
|
|
* Results from a **task** are passed to the next task.
|
|
* Passed or thrown errors in tasks get trapped with
|
|
* functions of arity 3 `function (err, res, cb)` called here **trap**.
|
|
* In case that there is no previous error, a **trap** acts as "no-op".
|
|
* In case that no **trap** is defined then the chain exits to an optional `callback`.
|
|
*
|
|
* @name connect
|
|
* @memberOf module:serial
|
|
* @static
|
|
* @method
|
|
* @param {...Function|Array} tasks - Arguments or Array of callback functions of type **task**
|
|
* `function (arg: any, cb: function)` or **trap** `function (err: <Error>, arg: any, cb: function)` where
|
|
* `arg` - an argument which is passed from one task to the other
|
|
* `err` - a trapped error from previous tasks
|
|
* `cb` - the callback function which needs to be called on completion
|
|
* @return {Function} composed function of `function (arg, cb)` where
|
|
* `arg` - initial argument which is passed from one task to the other
|
|
* `[callback]` - optional callback function `function(err: <Error>, res: any)`
|
|
* @example
|
|
* var c = connect(
|
|
* (res, cb) => { cb(null, res + 1) }, // task
|
|
* (err, res, cb) => { cb(null, res + 3) }, // trap - "no-op" here as there is no previous error
|
|
* (res, cb) => { cb(null, res * 2) } // task
|
|
* )
|
|
* c(2, function (err, res) {
|
|
* //> err = null
|
|
* //> res = 6
|
|
* })
|
|
*
|
|
* @example <caption>With error traps</caption>
|
|
* var c = connect(
|
|
* (res, cb) => { cb('error', res + 1) }, // task - error is passed to next task
|
|
* (res, cb) => { cb(null, res * 2) }, // task - "no-op", jumps over this task due to previous error
|
|
* (err, res, cb) => { cb(null, res + 3) }, // trap - error gets trapped here (arity === 3)
|
|
* (res, cb) => { cb(null, res * 2) } // task - continues
|
|
* )
|
|
* c(2, function (err, res) {
|
|
* //> err = null
|
|
* //> res = 12
|
|
* })
|
|
*
|
|
*/
|
|
function connect() {
|
|
for (var _len = arguments.length, tasks = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
tasks[_key] = arguments[_key];
|
|
}
|
|
|
|
if (tasks.length === 1 && Array.isArray(tasks[0])) {
|
|
tasks = tasks[0];
|
|
}
|
|
|
|
return function (arg, callback) {
|
|
var i = 0;
|
|
run(null, arg);
|
|
|
|
function run(err, res) {
|
|
var fn = tasks[i++];
|
|
|
|
try {
|
|
if (err) {
|
|
// search for next function of arity 3
|
|
while (fn && fn.length !== 3) {
|
|
fn = tasks[i++];
|
|
}
|
|
|
|
fn && fn(err, res, run);
|
|
} else {
|
|
// jump over all error traps
|
|
while (fn && fn.length > 2) {
|
|
fn = tasks[i++];
|
|
}
|
|
|
|
fn && fn(res, run); // step
|
|
}
|
|
} catch (e) {
|
|
run(e, res);
|
|
}
|
|
|
|
if (!fn) {
|
|
callback && callback(err, res);
|
|
}
|
|
}
|
|
};
|
|
} |