Chaining Promises
JS
R
JavaScriptIf you (really need) to chain promises without any libraries, please keep with the following approach. *spoiler alert: if possible avoid chaining promises, use BlueBird spread() operator or similar.
1function doThis(result) {
2 // ...
3}
4function doThat(result) {
5 // ...
6}
7function handleError(error) {
8 // ...
9}
10function done() {
11 // ...
12}
13
14return doSomething(foo)
15 .then(doThis)
16 .then(doThat)
17 .catch(handleError)
18 .finally(done);Created on 5/18/2018