When I found Q.delay() I thought it was a chainable delay behaving like the jQuery .delay() (
http://api.jquery.com/delay/)
However, it simply resolves a promise after a delay from the initial setup of the call. Meaning that
> function f(i){console.log(i++); return i;}
> Q(1).then(f).delay(1000).then(f).delay(1000).then(f).delay(1000).then(f).delay(1000).then(f)
2 through 5 are printed immediately. I was expecting .delay() to behave like
> function delay(i){return Q(i).delay(1000)}
> Q(1).then(f).then(delay).then(f).then(delay).then(f).then(delay).then(f).then(delay).then(f)
Here we see a 1 second delay between each number.
Basically what I would expect delay to be is
function delay(promise, timeout) {
if (timeout === void 0) {
deferred.resolve(promise);
when(promise, doDelay, doDelay, deferred.notify);
In other words, forward the resolution or rejection timeout milliseconds after it occurred. This is useful for tests and invalidating cache objects etc.
Is that an acceptable change in semantics? I think that people that were using delay() in the original sense were only using Q.delay, or didn't notice that the delays didn't add up.
Wout.