W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2014

Indexed DB Transactions vs. Microtasks

From: Joshua Bell <jsbell@google.com>
Date: Thu, 5 Jun 2014 12:59:26 -0700
Message-ID: <CAD649j7SsL8Q8b3g5FvbkbgT06-WPVD=gC7dMZuLiME=xAa=1A@mail.gmail.com>
To: "public-webapps@w3.org" <public-webapps@w3.org>
Playing with Promise wrappers for IDB, the intersection of IDBTransaction's
|active| state and microtask execution came up. Here are a couple of
interesting cases:

case 1:

  var tx;
  Promise.resolve().then(function() {
    tx = db.transaction(storeName);
    // tx should be active here...
  }).then(function() {
    // is tx active here?
  });

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?
    });
  };

In Chrome 35, the answers are "no", "no". This is because it was a
non-conforming Promise implementation, with the Promise callbacks not run
as microtasks. This was addressed in 36, so please disregard this behavior.

In Chrome 36, the answers are "yes", "yes".

In Firefox 29, the answers are "yes", "no".

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.

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?
Received on Thursday, 5 June 2014 19:59:54 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:24 UTC