Skip to content

Instantly share code, notes, and snippets.

@cetrix13
Last active September 12, 2019 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cetrix13/a87ab2da1dcfa78ba361fdbf7db0caeb to your computer and use it in GitHub Desktop.
Save cetrix13/a87ab2da1dcfa78ba361fdbf7db0caeb to your computer and use it in GitHub Desktop.
Function that repeats number of times requests to a server
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