-
-
Notifications
You must be signed in to change notification settings - Fork 641
Dexie.IncompatiblePromiseError
David Fahlander edited this page Apr 5, 2016
·
34 revisions
-
Error
-
Dexie.DexieError
- Dexie.IncompatiblePromiseError
-
Dexie.DexieError
Happens when returning an incompatible Promise from a transaction scope. You need to verify that you are returning an instance of Dexie.Promise from your transaction scope.
Dexie.Promises are compatible with other Promises, but in transaction scopes you must use Dexie.Promise only. Outside transaction scopes, you are free to mix with other promises. The reason is that Dexie's transaction scope needs to do the following:
- Make sure indexedDB transactions aren't committed too early
- Keep track of currently ongoing transaction for the particular scope.
- Detect whether a promise was uncaught and if so, abort the transaction.
db.transaction ('rw', db.friends, function() {
// Always use Dexie.Promise in the scope:
return Dexie.Promise.all ([
db.friends.put({name: "Foo"}),
db.friends.put({name: "Bar"})
]);
});
Easiest: Make your Dexie-facing module use Dexie.Promise for all async/await statements in current module.
import Dexie from 'dexie';
let Promise = Dexie.Promise; // Make async work with transactions in current module
async function putFriends() {
await db.transaction('rw', db.friends, async () => {
await db.friends.put({name: "Foo"});
await db.friends.put({name: "Bar"});
});
});
If you want to mix with other promises in the same module, you can just declare Promise where needed - the same level as where you call db.transaction():
import Dexie from 'dexie';
async function putFriends() {
// Make async/await work with transactions below current scope
let Promise = Dexie.Promise;
await db.transaction('rw', db.friends, async () => {
await db.friends.put({name: "Foo"});
await db.friends.put({name: "Bar"});
});
}
// The final result will be standard promise. And this is ok.
assert (putFriends() instanceof window.Promise);
Dexie.js - minimalistic and bullet proof indexedDB library