-
Only the original promise (created with new) can control when it will resolve/reject (callee decide)
-
Each subsequent promise (subscriber) created with then will either resolve when the
onFulfilled
andonRejected
return OR if no handler resolve with the same value as the parent -
A promise should NEVER be resolved with another promise.
-
Based on callbacks:
p0 = resolve(p1) => resolve(p2) => ... => resolve(pn)
thenp0
must wait until pn resolves.p0 .. p(n-1)
with resolve with same value aspn
-
p1 = p0.then()
p2 = p0.then()
...
pn = p0.then()
In this case, p1...pn
must wait until p0
resolved.
- p1 => resolve(p2)
- p1 => resolve(42).then(42 => return 42 + 1)