Re: [w3c/ServiceWorker] async waitUntil microtask issue (#1213)

I think our spec wording is a little wrong here.

> Upon fulfillment or rejection of f, queue a microtask to run these substeps:

[Fulfillment](https://www.w3.org/2001/tag/doc/promises-guide/#upon-fulfillment) already queues a microtask, so we may be doing something redundant. Unless we're intentionally adding a microtask to a microtask, which I don't think we are.

I'm struggling to get my head around this. I don't think this should work:

```js
const p = doSomething();
event.waitUntil(p);
p.then(() => event.waitUntil(doSomethingElse()));
```

Because the pending promises count will be 0 when `event.waitUntil` is called. This is because the spec's microtask is in the queue before the `p.then` handler. Whereas:

```js
const p = doSomething();
p.then(() => event.waitUntil(doSomethingElse()));
event.waitUntil(p);
```

…would work, since the `p.then` handler is in the queue before the spec's microtask.

I guess it's a bit of a gotcha, but it'll fail consistently.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1213#issuecomment-341504071

Received on Thursday, 2 November 2017 17:47:54 UTC