Skip to content

Instantly share code, notes, and snippets.

@MohammadAzimi
Last active November 17, 2021 09:59
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 MohammadAzimi/30531e1696deee6cc0050f3679856257 to your computer and use it in GitHub Desktop.
Save MohammadAzimi/30531e1696deee6cc0050f3679856257 to your computer and use it in GitHub Desktop.
// 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');
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