Created
October 12, 2025 13:29
-
-
Save IlyaIvanchikov/3c2f656f136fcb49e4c34b8094e843d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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