Skip to content

async waitUntil() does not allow extension on final promise resolution? #1039

@wanderview

Description

@wanderview

I feel like we discussed this case at one point, but can't find where:

addEventListener('fetch', evt => {
  // keep alive the SW based on some promise
  let resolveOuterPromise;
  let p = new Promise(resolve => resolveOuterPromise = resolve);
  evt.waitUntil(p);

  // Code can be defined to run on the final keep alive promise resolution that
  // then keeps the SW alive again.
  p.then(_ => {
    // I think the spec says this should throw, but I thought we agreed this should work.
    evt.waitUntil(fetch(evt.request));
  });

  // promise resolves at some point...
  setTimeout(_ => resolveOuterPromise(), 100);
});

I don't think the spec allows this as currently written. Step 4 here:

https://w3c.github.io/ServiceWorker/#extend-service-worker-lifetime-algorithm

Unsets the flag allowing extension immediately after the current set of extension promises settles in step 2. I think this blocks the addition of new extension promises?

Or is there something which guarantees other .then() handlers will run between step 2 and 3 here?

I think we should either explicitly have a microtask to run step 3/4 or run add a comment about some hidden invariant which results in this outcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions