mirror of
https://github.com/azure/login.git
synced 2026-06-07 19:47:09 +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>
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import { _times } from './_utils'
|
|
|
|
/**
|
|
* Run `task` repeatedly until number `times` is reached.
|
|
*
|
|
* Stops at the first error encountered.
|
|
* An optional `lag` between retries may be used.
|
|
*
|
|
* @name times
|
|
* @memberOf module:serial
|
|
* @static
|
|
* @method
|
|
* @param {Number|Object} times - runs `times` times. If `times < 0` then "times" cycles endlessly until an error occurs.
|
|
* @param {Number} [times.times=0] - max. number of retries
|
|
* @param {Number} [times.lag=0] - time-lag in ms between retries
|
|
* @param {Function} task - iterator function of type `function (cb: Function, index: Number)`
|
|
* @param {Function} [callback] - optional callback `function (errors: Error, result: Array<any>)`
|
|
*
|
|
* @example
|
|
* let arr = []
|
|
* times({times: 4, lag: 100}, // 4 times with 100ms time-lag between retries
|
|
* (cb, index) => {
|
|
* arr.push(index)
|
|
* cb(null, index)
|
|
* }, (err, res) => {
|
|
* //> err = null
|
|
* //> res = 3
|
|
* //> arr = [0, 1, 2, 3]
|
|
* }
|
|
* )
|
|
*/
|
|
export default function times (num, task, callback) {
|
|
let i = 0
|
|
const { times, lag, fn } = _times(num)
|
|
|
|
if (times) {
|
|
run()
|
|
} else {
|
|
callback && callback()
|
|
}
|
|
|
|
function cb (err, res) {
|
|
if (err || (times > 0 && i >= times)) {
|
|
callback && callback(err, res)
|
|
} else {
|
|
fn(() => {
|
|
run()
|
|
}, lag)
|
|
}
|
|
}
|
|
|
|
function run () {
|
|
task(cb, i++)
|
|
}
|
|
}
|