From 09058eab1563d3b4eaee9c9dd3a9a03705bac132 Mon Sep 17 00:00:00 2001 From: dfahlander Date: Tue, 28 Nov 2023 00:59:19 +0100 Subject: [PATCH] Corrected behavior of DexiePromise.finally(): 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. --- src/helpers/promise.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/helpers/promise.js b/src/helpers/promise.js index 049a53787..a7f4a7dc3 100644 --- a/src/helpers/promise.js +++ b/src/helpers/promise.js @@ -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)); }); },