inexorabletash / indexeddb-promises

Proposal for incremental support for Promises in the Indexed DB API
48 stars 2 forks source link

Return value of waitUntil()? #3

Open inexorabletash opened 9 years ago

inexorabletash commented 9 years ago

Options include:

  1. a Promise dependent on the promise the transaction is waiting on
  2. just whatever is passed in
  3. undefined

1 is redundant with .complete 2 is not terribly helpful 3 is what ExtendableEvent is defined as

So 3 probably makes the most sense and leaves room to change it in the future.

inexorabletash commented 9 years ago

In email to public-webapps, @domenic suggests returning tx.complete as a convenience.

inexorabletash commented 8 years ago

As hinted at in #9 it may be convenient to make it a pass-through so you can write e.g.

  const url = await tx.objectStore('urls').get(key);
  const request = await tx.waitUntil(fetch(url));
  const text = await tx.waitUntil(request.text());
  tx.objectStore('bodies').put(text, key);

.... which looks better than the "IIAFE" alternative:

tx.waitUntil((async () => {
  const url = await tx.objectStore('urls').get(key);
  const request = await fetch(url);
  const text = await request.text();
  await tx.objectStore('bodies').put(text, key);
})());