Re: [w3c/ServiceWorker] event.waitUntil/respondWith vs return promise (#1148)

> But a fetch event has both respondWith and waitUntil. How can one returned promise be used for both?

`return` for `respondWith`. Wait till all the tasks have completed. [See:](https://twitter.com/pemrouz/status/849068273568288768)

> was thinking cache async, but return response. Can browser not kill SW based on tasks left to complete? e.g. node doesn't kill if setTimeout or other cbs pending, no "waitUntil". cache.put alone should suffice, no kill till completes

---

> fwiw the general problem here is event handler return values are already used for preventing default. 

Sure, but it seems like it should be fairly simple to not confuse the two. For example, if the promise return value was spec'ed just for ExtendableEvent, it would just make it work for SW and newer API's whilst leaving the older stuff as is.

> Making them do something different events seems a bit weird.

I imagine very few people actually use event return values to prevent default vs `.preventDefault()` and will be confused by this or complain about it. Or, if you took a poll, I imagine most people would strongly prefer to use async/await throughout vs return values in SW code. 

On the other hand, people are pretty used to the event loop running till completion and will find the default behaviour very surprising. There will be lots of confusion and debugging when event handlers silently skip and finish tasks. It will require constantly changing between paradigms. 

In fact, now I think about it, `event.waitUntil` seems like completely redundant information. When would you ever deliberately want to terminate before some other task you've scheduled?

> Also, if you don't want to handle a fetch, you just avoid calling respondWith. This gets more complicated with return values, as functions always return.

This could match to not returning a promise, or a promise that resolves to undefined?

-- 
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/1148#issuecomment-302950819

Received on Sunday, 21 May 2017 17:32:15 UTC