Open inexorabletash opened 8 years ago
Another data point in favor of behavior 1:
async function doStuff(db, url) {
const tx = db.transaction('store', 'readwrite');
const store = tx.objectStore('store');
let record = await store.get(url);
if (!record) {
const p = fetch(url); // Pretend this yields a cloneable thing
tx.waitUntil(p);
const r = await p;
// NOTE: if waitUntil(x) returns x, then above can be just:
// const r = await tx.waitUntil(fetch(url));
// NOTE: extend lifetime promises have fulfilled, but don't want to commit yet!
store.put(r, url);
}
return record;
}
If you don't transition back to "active" then you must write the waitUntil()
so that it encompasses the entire promise chain. If you do transition back to "active" then it is possible to just waitUntil()
a non-IDB operation to "bring it into the fold".
Note that the or "active" if we happen to be in an IDB event dispatch clause needs handling even in the case where there are no more outstanding requests. An important case to get right: the transaction is waiting on one of its own requests. The timing of the dispatch vs. resolution is also critical there - don't want to try and commit too early, nor forget to commit.
Need to specify the behavior for:
And also:
The plausible behaviors I can think of are:
waitUntil()
calls."InvalidStateError"
.The former feels more natural to me, but the second makes sense if you consider using
waitUntil()
to build explicitly committing transactions:(But I still lean towards the former)