Created
January 31, 2020 12:33
-
-
Save pasmat/a9251232da23069b27e6924ce857fb46 to your computer and use it in GitHub Desktop.
a javascript function that returns a Promise which includes artificial latency of x seconds.
This file contains hidden or 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
/* | |
used such as.. | |
fetch("https://google.com") | |
.then(function (response) { | |
return pausePromise(response, 5) | |
}) | |
.then(function (response) { | |
console.log(response); | |
}); | |
to include artificial latency of 5 seconds | |
*/ | |
function pausePromise(response, seconds) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
resolve(response) | |
}, seconds * 1000); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment