I\'m trying to do the following but it isn\'t working. How can I adjust the code to have a delay between .then
and .done
?
myServi
You can create a .delay()
function set at Promise.prototype
which returns a new Promise
having value of original promise.
Promise.prototype.delay = function(t) {
return this.then(function(data) {
return new Promise(function(resolve) {
setTimeout(resolve, t || 0, data);
})
})
};
Promise.resolve(123)
.delay(6000)
.then(function(data) {
console.log(data)
});