Skip to content

Instantly share code, notes, and snippets.

@pasmat
Created January 31, 2020 12:33
Show Gist options
  • Save pasmat/a9251232da23069b27e6924ce857fb46 to your computer and use it in GitHub Desktop.
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.
/*
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