CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
whilst.js78 linesDownload Raw Back to async
1'use strict';2 3Object.defineProperty(exports, "__esModule", {4    value: true5});6 7var _onlyOnce = require('./internal/onlyOnce.js');8 9var _onlyOnce2 = _interopRequireDefault(_onlyOnce);10 11var _wrapAsync = require('./internal/wrapAsync.js');12 13var _wrapAsync2 = _interopRequireDefault(_wrapAsync);14 15var _awaitify = require('./internal/awaitify.js');16 17var _awaitify2 = _interopRequireDefault(_awaitify);18 19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }20 21/**22 * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when23 * stopped, or an error occurs.24 *25 * @name whilst26 * @static27 * @memberOf module:ControlFlow28 * @method29 * @category Control Flow30 * @param {AsyncFunction} test - asynchronous truth test to perform before each31 * execution of `iteratee`. Invoked with (callback).32 * @param {AsyncFunction} iteratee - An async function which is called each time33 * `test` passes. Invoked with (callback).34 * @param {Function} [callback] - A callback which is called after the test35 * function has failed and repeated execution of `iteratee` has stopped. `callback`36 * will be passed an error and any arguments passed to the final `iteratee`'s37 * callback. Invoked with (err, [results]);38 * @returns {Promise} a promise, if no callback is passed39 * @example40 *41 * var count = 0;42 * async.whilst(43 *     function test(cb) { cb(null, count < 5); },44 *     function iter(callback) {45 *         count++;46 *         setTimeout(function() {47 *             callback(null, count);48 *         }, 1000);49 *     },50 *     function (err, n) {51 *         // 5 seconds have passed, n = 552 *     }53 * );54 */55function whilst(test, iteratee, callback) {56    callback = (0, _onlyOnce2.default)(callback);57    var _fn = (0, _wrapAsync2.default)(iteratee);58    var _test = (0, _wrapAsync2.default)(test);59    var results = [];60 61    function next(err, ...rest) {62        if (err) return callback(err);63        results = rest;64        if (err === false) return;65        _test(check);66    }67 68    function check(err, truth) {69        if (err) return callback(err);70        if (err === false) return;71        if (!truth) return callback(null, ...results);72        _fn(next);73    }74 75    return _test(check);76}77exports.default = (0, _awaitify2.default)(whilst, 3);78module.exports = exports.default;
basant307/AI_Governance_Project · CoolFace