Last active
September 12, 2019 20:04
-
-
Save cetrix13/a87ab2da1dcfa78ba361fdbf7db0caeb to your computer and use it in GitHub Desktop.
Function that repeats number of times requests to a server
This file contains 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 URL = 'https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=56.84,55.27,33.48,41.48'; | |
function makeRequest(url, num) { | |
return new Promise(function(resolve, reject) { | |
fetch(url) | |
.then(result => resolve(result)) | |
.catch(err => { | |
if (num === 1) return reject(err); | |
makeRequest(url, num - 1).then(resolve).catch(reject); | |
}) | |
}); | |
} | |
/* simple version | |
function makeRequest(url, n) { | |
return fetch(url).catch(function(error) { | |
if (n === 1) throw error; | |
return makeRequest(url, n - 1); | |
}); | |
} | |
*/ | |
makeRequest(URL, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment