/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/env/lib/retry.js
29 строк
740 B
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
'use strict'; const util = require( 'util' ); /** * Promisified dependencies */ const sleep = util.promisify( setTimeout ); /** * Performs the given action again and again until it does not throw an error. * * @param {Function} action The action to perform. * @param {Object} options * @param {number} options.times How many times to try before giving up. * @param {number} [options.delay=5000] How long, in milliseconds, to wait between each try. */ module.exports = async function retry( action, { times, delay = 5000 } ) { let tries = 0; while ( true ) { try { return await action(); } catch ( error ) { if ( ++tries >= times ) { throw error; } await sleep( delay ); } } };