Skip to content

Commit

Permalink
Corrected behavior of DexiePromise.finally():
Browse files Browse the repository at this point in the history
If the onFinally callback returns a promise, wait for it before returning value. And if that promise rejects, return that rejection instead. This all according to spec. Earlier version did just call onFinally() and then return the original value - it did not allow for the onFinally to perform async work before continuing and it did not reject if the onFinally returned rejected promise or threw error.
  • Loading branch information
dfahlander committed Nov 29, 2023
1 parent b7d2d56 commit 09058ea
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/helpers/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,9 @@ props(DexiePromise.prototype, {

finally: function (onFinally) {
return this.then(value => {
onFinally();
return value;
return DexiePromise.resolve(onFinally()).then(()=>value);
}, err => {
onFinally();
return PromiseReject(err);
return DexiePromise.resolve(onFinally()).then(()=>PromiseReject(err));
});
},

Expand Down

0 comments on commit 09058ea

Please sign in to comment.