Reputation: 4830
Is there any way to know when all requests have finished but before the transaction commits? The transaction.oncomplete
event does not allow for any additional logic to run while still calling transaction.abort()
. So, a better way is to use the equivalent of transaction.completing
(I made this up) which will only fire after all requests were complete but still allow for transaction.abort()
to be called.
http://www.w3.org/TR/IndexedDB/
In general, this should be considered good practice. In the most common case simple syntax errors would not leave the database in a inconsistent case.
Upvotes: 1
Views: 145
Reputation: 2720
Is there any way to know when all requests have finished but before the transaction commits?
Yes but you have to write code that listens to all your operations' success
or error
events. There is no beforecommit
event as you would like. But feel free to make a case for its inclusion on public-webapps.
In the most common case simple syntax errors would not leave the database in a inconsistent case.
How can the database get into an inconsistent state? That's why the error
event exists and by default causes the transaction to abort. See http://w3c.github.io/IndexedDB/#dfn-fire-an-error-event.
Upvotes: 2