Promises icon indicating copy to clipboard operation
Promises copied to clipboard

IDBTransaction should become a Future as well

Open inexorabletash opened this issue 12 years ago • 1 comments

In the "reworked APIs" section, IDBRequest becomes a subclass of Future.

IDBTransaction behaves similarly, although it's not as simple a type as a IDBRequest. A transaction has a lifetime bounded by other asynchronous activity, after which it completes successfully ("complete" event) or fails ("abort" event), and in both cases action is likely to be taken by the script.

With current IDB you write:

  tx = db.transaction(...);
  tx.objectStore(...).put(...);
  tx.oncomplete = function() { alert("yay, done"); };

I'd expect a Future-ish IDB to let me write:

  tx = db.transaction(...);
  tx.objectStore(...).put(...);
  tx.then(function() { alert("yay, done"); });

... which of course gets more useful when you have join() operations letting you wait on multiple futures and all that other goodness.

inexorabletash avatar Mar 28 '13 17:03 inexorabletash

This is a good point, although I'd also like a more explicit API that provides some control over how to extend the lifetime of a transaction. I've suggested to @sicking in the past that we add something like a .transact() method (in the context of LSA which could vend a Promise. But you're right: the existing thigns that vend transactions should change to vend Promises. Patches welcome.

slightlyoff avatar Jun 07 '13 11:06 slightlyoff