I\'d like to define a function that takes a promise, and returns an identical promise, except that the returned promises resolves an arbitrary timeout; my code looks something l
I hope you find the implementation of delay
in Q insightful. https://github.com/kriskowal/q/blob/master/q.js#L1629-L1637
Q.delay = function (object, timeout) {
if (timeout === void 0) {
timeout = object;
object = void 0;
}
return Q(object).delay(timeout);
};
Promise.prototype.delay = function (timeout) {
return this.then(function (value) {
var deferred = defer();
setTimeout(function () {
deferred.resolve(value);
}, timeout);
return deferred.promise;
});
};