From 71e95deceb3d41b34120c09d8c5f508461a2beb8 Mon Sep 17 00:00:00 2001 From: remorses Date: Thu, 16 Nov 2023 15:00:30 +0100 Subject: [PATCH] add support for async functions inside doc.transact --- src/utils/Transaction.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/Transaction.js b/src/utils/Transaction.js index 5b93369f..01462500 100644 --- a/src/utils/Transaction.js +++ b/src/utils/Transaction.js @@ -436,7 +436,13 @@ export const transact = (doc, f, origin = null, local = true) => { // observes throw errors. // This file is full of hacky try {} finally {} blocks to ensure that an // event can throw errors and also that the cleanup is called. - cleanupTransactions(transactionCleanups, 0) + if (typeof result?.then === 'function' && result?.constructor?.name === 'Promise') { + result.then(() => { + cleanupTransactions(transactionCleanups, 0) + }) + } else { + cleanupTransactions(transactionCleanups, 0) + } } } }