in public/dexie.js [2434:2509]
function enterTransactionScope() {
return Promise.resolve().then(function () {
// Keep a pointer to last non-transactional PSD to use if someone calls Dexie.ignoreTransaction().
var transless = PSD.transless || PSD;
// Our transaction.
//return new Promise((resolve, reject) => {
var trans = db._createTransaction(
mode,
storeNames,
globalSchema,
parentTransaction
);
// Let the transaction instance be part of a Promise-specific data (PSD) value.
var zoneProps = {
trans: trans,
transless: transless,
};
if (parentTransaction) {
// Emulate transaction commit awareness for inner transaction (must 'commit' when the inner transaction has no more operations ongoing)
trans.idbtrans = parentTransaction.idbtrans;
} else {
trans.create(); // Create the backend transaction so that complete() or error() will trigger even if no operation is made upon it.
}
// Support for native async await.
if (scopeFunc.constructor === AsyncFunction) {
incrementExpectedAwaits();
}
var returnValue;
var promiseFollowed = Promise.follow(function () {
// Finally, call the scope function with our table and transaction arguments.
returnValue = scopeFunc.call(trans, trans);
if (returnValue) {
if (returnValue.constructor === NativePromise) {
var decrementor = decrementExpectedAwaits.bind(null, null);
returnValue.then(decrementor, decrementor);
} else if (
typeof returnValue.next === "function" &&
typeof returnValue.throw === "function"
) {
// scopeFunc returned an iterator with throw-support. Handle yield as await.
returnValue = awaitIterator(returnValue);
}
}
}, zoneProps);
return (
returnValue && typeof returnValue.then === "function"
? // Promise returned. User uses promise-style transactions.
Promise.resolve(returnValue).then(function (x) {
return trans.active
? x // Transaction still active. Continue.
: rejection(
new exceptions.PrematureCommit(
"Transaction committed too early. See http://bit.ly/2kdckMn"
)
);
})
: // No promise returned. Wait for all outstanding promises before continuing.
promiseFollowed.then(function () {
return returnValue;
})
)
.then(function (x) {
// sub transactions don't react to idbtrans.oncomplete. We must trigger a completion:
if (parentTransaction) trans._resolve();
// wait for trans._completion
// (if root transaction, this means 'complete' event. If sub-transaction, we've just fired it ourselves)
return trans._completion.then(function () {
return x;
});
})
.catch(function (e) {
trans._reject(e); // Yes, above then-handler were maybe not called because of an unhandled rejection in scopeFunc!
return rejection(e);
});
});
}