Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDBTransaction should become a Future as well #49

Open
inexorabletash opened this issue Mar 28, 2013 · 1 comment
Open

IDBTransaction should become a Future as well #49

inexorabletash opened this issue Mar 28, 2013 · 1 comment

Comments

@inexorabletash
Copy link

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.

@slightlyoff
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants