Last active
November 17, 2021 09:59
-
-
Save MohammadAzimi/30531e1696deee6cc0050f3679856257 to your computer and use it in GitHub Desktop.
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
// curring fuction; | |
// mix of closure; | |
function createUrl(baseUrl, protocol = 'https') { | |
// we can have some other process here | |
return function (path) { | |
return `${protocol}://${baseUrl}/${path}`; | |
} | |
} | |
const createClubUrl = createUrl('club.0-1.ir'); | |
const createSamfonyUrl= createUrl('samfonyIp', 'http'); | |
const samfonyLoginUrl = createSamfonyUrl('action=login'); | |
const samfonyGetTempsUrl = createSamfonyUrl('action=getTemp'); | |
const clubPointUrl = createClubUrl('mypoints'); |
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
function fetchWithTimeout(url, options, timeout = 0) { | |
return Promise.race([ | |
fetch(url, options), | |
new Promise((_, reject) => { | |
if (timeout > 0) { | |
return setTimeout(() => reject(new Error('TimeoutError')), timeout); | |
} | |
}), | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment