Search⌘ K
AI Features

Return Promises from finally()

Understand how returning promises from finally settlement handlers works in JavaScript. Explore how fulfilled promises from finally are ignored, while rejected promises cause the chain to reject. Learn how this affects sequencing asynchronous operations within chained promises.

Promise chains returning promises

Returning a promise from a settlement handler using finally() also exhibits some different behavior than using then() or catch(). First, if we return a fulfilled promise from a settlement handler, then that promise is ignored in favor of the value from the original promise, as in this example:

Javascript (babel-node)
const promise = Promise.resolve(11);
promise.finally(() => {
return Promise.resolve(22);
}).then(value => {
console.log(value); // 11
});

In this example, the ...