Indexed transaction in a transaction. Incomplete with multiple actions

Question: how is IDBTransaction - the kind that you get from IDBDatabase, we will call it type A - to know when to call oncomplete, if it can include an arbitrary number of IDBTransaction (type B) children?

First, you get your IDBTransaction of type A from the database connection:

const transA = IDBDatabase.transaction(storeName, mode);

This IDBT can carry the event oncomplete, and, presumably, it fires when the complete transaction is completed. But you use this IDBT to “trigger” real transactions through one or more of the IDBObjectStores found:

const store = transA.objectStore(storeName);
const transB1 = store.delete(key);
const transB2 = store.add(item);

Now transB1and transB2also are instances of IDBTransaction, which can have their own handlers oncomplete. The idea of ​​a parent transaction here, as I understand it, is that it allows an aggregated transaction to be atomic; if transB1 succeeds but transB2 fails, transB1 rolls back. Good. Therefore, we are usually more interested in listening to the parent, not the children, as this is what tells us whether it really succeeded.

A trap I don't get: no method closeor doneor finishor anything else. So how transAdoes it really know when to run oncomplete?

, , . , ? ( , IndexedDB -JS, , , , DOM .) ?

+4
2

.

, , , , , . - , , "" (, transaction.on('complete', ...))), , , , indexedDB API, .: (

( , , , - .)

+2

DB API . , , , , SQL. , /, , .

, , API . , , , , , .

, ? ?

+1

Source: https://habr.com/ru/post/1606029/


All Articles