JS: Promise .prototype .then
Promise .prototype .then
syntax:
promise_object.then(f1,f2)
f1 and f2 are both functions of 1 parameter.
f1 and f2 are optional.
the then-method sets up handler functions to call on promise_object state. f1 or f2 is called as soon as the promise is settled.
- when the promise_object is fulfilled, f1 is called with an arg xresult, where xresult is the arg passed to resolve function in the promise f_executor function body.
- when the promise_object is rejected, f2 is called with an arg xerror, where xerror is the arg passed to reject function in the promise f_executor function body.
The then-method returns a new promise object. (so it can be chained)
Throwing inside f1 or f2 in promise_object.then(f2,f2) rejects the promise created by the then-method.