mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
fixed sync
This commit is contained in:
@@ -122,38 +122,43 @@ async function wrap(func) {
|
||||
}
|
||||
}
|
||||
|
||||
let transactionActive = false;
|
||||
let transactionPromise = null;
|
||||
|
||||
async function doInTransaction(func) {
|
||||
while (transactionPromise !== null) {
|
||||
while (transactionActive) {
|
||||
await transactionPromise;
|
||||
}
|
||||
|
||||
const error = new Error(); // to capture correct stack trace in case of exception
|
||||
|
||||
transactionActive = true;
|
||||
transactionPromise = new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
|
||||
await beginTransaction();
|
||||
|
||||
await func();
|
||||
|
||||
await commit();
|
||||
|
||||
transactionActive = false;
|
||||
resolve();
|
||||
transactionPromise = null;
|
||||
}
|
||||
catch (e) {
|
||||
log.error("Error executing transaction, executing rollback. Inner exception: " + e.stack + error.stack);
|
||||
|
||||
await rollback();
|
||||
|
||||
transactionActive = false;
|
||||
resolve();
|
||||
transactionPromise = null;
|
||||
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
if (transactionActive) {
|
||||
await transactionPromise;
|
||||
}
|
||||
}
|
||||
|
||||
dbReady
|
||||
|
||||
Reference in New Issue
Block a user