Closed prassh123 closed 7 years ago
$indexedDB.openStore('abcd', function (readStore) {
// do stuff
}).catch( function (failureReason) {
// handle error
});
openStore actually just returns a promise. I don't remember exactly why I had implemented openStore as a callback instead of promise style but I'm sure there was a good reason.
Ahhh yes that's right. You actually get a transaction out of the system for the stores requested. Your function needs to execute before control can be fully given back to you. The problem really is more around how javascript stacks promises. The library needs to execute your callback and then commit the transaction. If you do a .then() on the returned promise from openStore() you are then guaranteed that your transaction has successfully committed to the underlying store.
This may perhaps be unclear when reading the project documentation. Feel free to open a PR in a way that you feel clarifies the documentation in this regard.
Thanks @bramski. Catching the error (as you had described above) works well.
I was wondering if there is a way to detect failure to open the store. One case that i ran into was specifying an incorrect data store name as below. In that scenario, the callback was never executed.