What happens when I return a promise from a .then
method which is wrapped in another object like:
somepromise
.then((step1Result) => {
return {
'val1' : synchronousCalculation(),
'val2' : asyncCalculation() // << THIS HERE
};
})
.then((result) => {
// PATH2
});
i.e. is PATH2
guaranteed to have a settled promise in result['val2']
?
A simpler situation is always guaranteed as mentioned in this question where the top answer mentions this article:
When you return something from a then() callback, it's a bit magic. If you return a value, the next then() is called with that value. However, if you return something promise-like, the next then() waits on it, and is only called when that promise settles (succeeds/fails)
Note that I'm avoiding to call await asyncCalculation()
because I cannot turn the whole method into async
, there's too much that would have to change if I did that.