I'm assuming Q.all([p1, p2, p3]).then(f)
is no different than
p1.then(function () {
p2.then(function () {
p3.then(f);
});
});
Because when p1
, p2
and p3
are created the async calls have already been made and we just have to wait for all of them to resolve and the order doesn't matter.
Am I correct?
If so, I've been looking at kriskowal's all
implementation. I thought it would be something similar (chaining promises using then
). But I find it to be implemented completely differently? Why is that?
Edit:
Let me be a little more clear. Say p1, p2, p3 resolve in 100ms, 200ms, 300ms respectively. The order of waiting for their response makes no differens
p1.then(function () {
// we're here at 100ms
p2.then(function () {
// 100ms later we're here
p3.then(f); // f gets called 100ms later (at 300ms)
});
});
p3.then(function () {
// we're here at 300ms
p2.then(function () {
// boom! resolves in a snap
p1.then(f); // f also gets called instantly (at 300ms)
});
});
In both examples we only wait 300ms for all three promises to resolve.