Skip to content

Instantly share code, notes, and snippets.

@leolanese
Last active May 18, 2020
Embed
What would you like to do?
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