Created
December 4, 2019 15:18
-
-
Save Andy-set-studio/204ab4d620968190f7f6f0a6b36d6211 to your computer and use it in GitHub Desktop.
Sleep fetch function
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
/** | |
* Returns a fetch request after a defined timeout | |
* | |
* @param {String} url The url that you’re fetching | |
* @param {Object} options={} Fetch API parameters | |
* @param {Number} timeout=window.sleepFetchTimeout||1000 You can completely override the timeout globally with window.sleepFetchTimeout | |
* @returns {Promise} | |
*/ | |
const sleepFetch = (url, options = {}, timeout = window.sleepFetchTimeout || 0) => { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(fetch(url, options)); | |
}, timeout); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment