Last active
May 18, 2020 09:06
-
-
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)
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
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