Skip to content

Instantly share code, notes, and snippets.

@leolanese
Last active May 18, 2020 09:06
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 leolanese/b5c6521a21af1651196907279b113835 to your computer and use it in GitHub Desktop.
Save leolanese/b5c6521a21af1651196907279b113835 to your computer and use it in GitHub Desktop.
delay a Promise and log the time it takes to fulfill (legacy way)
function delayPromise(delay, value) {
console.time();
// using built-in Promise constructor-function/class.
return new Promise(function(resolve) {
setTimeout(function() {
console.timeEnd();
resolve(value);
}, delay);
});
}
var promise = delayPromise()
promise.then(function(returnedValue) {
console.log(returnedValue)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment