Re: Indexed DB Transactions vs. Microtasks

On Thu, Jun 5, 2014 at 12:59 PM, Joshua Bell <jsbell@google.com> wrote:
> case 1:
>
>   var tx;
>   Promise.resolve().then(function() {
>     tx = db.transaction(storeName);
>     // tx should be active here...
>   }).then(function() {
>     // is tx active here?
>   });
>
> For case 1, ISTM that "yes" matches the IDB spec, since control has not
> returned to the event loop while the microtasks are running. Implementations
> appear to agree.

Yes. I believe that this is what the spec currently calls for.

However I think it would actually be good to change the spec to say
that the transaction is closed at the end of the current microtask.

When we originally designed microtasks for Mutation Observers, one of
the goals was to ensure that there were not accidental
interdependencies between different event handlers to the same event.
By flushing end-of-microtask work after each event handler you ensure
that each event handler gets a clean slate.

I realize that this is a backwards-incompatible change. However it
seems pretty unlikely to break any existing content. So it'd be nice
to give it a try.

> case 2:
>
>   var tx = db.transaction(storeName);
>   var request = tx.objectStore(storeName).get(0);
>   request.onsuccess = function() {
>     // tx should be active here...
>     Promise.resolve().then(function() {
>       // is tx active here?
>     });
>   };
>
> For case 2, it looks like implementations differ on whether microtasks are
> run as part of the event dispatch. This seems to be outside the domain of
> the IDB spec itself, somewhere between DOM and ES. Anyone want to offer an
> interpretation?

I agree that this falls outside of the domain of the IDB spec. I admit
I would have preferred if the .then handler never sees an active
transaction, rather than have that depend on if resolving the promise
happens synchronously or asynchronously...

I don't know how to define that in a sane manner though.

And I have no idea how Firefox's current implementation appears to
manage to accomplish that.

/ Jonas

Received on Saturday, 7 June 2014 00:52:30 UTC