I am facing a situation where an api call returns data asynchronously and I have 2 methods that need to execute after the call is completed. However, these methods do not generate new promises on their own.
Can
const foo = new Promise(…);
foo.then(() => {
console.log("foo");
console.log("bar")
})
Be more advantageous than
const foo = new Promise(…);
foo
.then(() => console.log("foo"))
.then(() => console.log("bar"))
?
I understand that chaining then statements can be useful when the first one returns a promise, but is there any benefit to chaining then statements when the initial one does not return a promise?
One possible advantage could be more precise error control:
const foo = new Promise(…);
foo
.then(() => throw error("Whoopsie"))
.catch(e => handle(e))
.then(() => throw error("Daisy"))
.catch(e => handle(e))