mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports["default"] = whilst;
|
|
|
|
var _until = _interopRequireDefault(require("./until"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
|
|
/**
|
|
* Run `task` repeatedly until `test` returns `false`.
|
|
* Calls `callback` at the first error encountered.
|
|
*
|
|
* @name whilst
|
|
* @memberOf module:serial
|
|
* @static
|
|
* @method
|
|
* @param {Function} test - test function `function (index: number)`. If return value is `false` then `callback` gets called
|
|
* @param {Function} task - iterator function of type `function (cb: Function, index: Number)`
|
|
* @param {Function} [callback] - optional callback `function (errors: Error, result: any)` from last callback.
|
|
*
|
|
* @example
|
|
* let arr = []
|
|
* whilst(
|
|
* (index) => (index < 4), // test
|
|
* (cb, index) => { // task
|
|
* arr.push(index)
|
|
* cb(null, index)
|
|
* }, (err, res) => { // callback
|
|
* //> err = null
|
|
* //> res = 3
|
|
* //> arr = [0, 1, 2, 3]
|
|
* }
|
|
* )
|
|
*/
|
|
function whilst(test, task, callback) {
|
|
(0, _until["default"])(function (n) {
|
|
return !test(n);
|
|
}, task, callback);
|
|
} |