Skip to content

Instantly share code, notes, and snippets.

@IlyaIvanchikov
Created October 12, 2025 12:38
Show Gist options
  • Select an option

  • Save IlyaIvanchikov/17353c1ba8808218768e1499afaa9b4a to your computer and use it in GitHub Desktop.

Select an option

Save IlyaIvanchikov/17353c1ba8808218768e1499afaa9b4a to your computer and use it in GitHub Desktop.
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
async function simpleRetry(fn, retries = 3, delay = 1000) {
try {
return await fn();
} catch (error) {
if (retries <= 0) throw error;
await sleep(delay)
return simpleRetry(fn, retries - 1, delay);
}
}
// Пример использования
const fetchSomeData = async () => {
return simpleRetry(async () => {
const response = await fetch('https://api.example.com/data');
return response.json();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment