You can wrap a transaction in a promise like this:
var tx = db.transaction(scope, mode); var p = new Promise(function(resolve, reject) { tx.onabort = function() { reject(tx.error); }; tx.oncomplete = function() { resolve(); }; });
Now p will allow / reject when the transaction completes / aborts. This way you can execute arbitrary logic in transaction tx and p.then(...) and / or pass the dependent promise to e.respondWith() or e.waitUntil() , etc.
As other commentators note, we really need to promise IndexedDB. But the composition of his autocommit model after the task and the microtask queues that use Promises make it ... non-trivial for this, without a fundamental API replacement. But (as a developer and one of the specification editors), I am actively prototyping some ideas.
Joshua bell
source share