- From: Alfred Morgan <notifications@github.com>
- Date: Mon, 27 Nov 2017 05:48:35 +0000 (UTC)
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Monday, 27 November 2017 05:49:18 UTC
Calling `waitUntil()` on `event` doesn't sound right to me. Since the event has already fired, how is it that it has to "wait"? In addition, the code that one has to write is bulkier using `waitUntil()` and `respondWith()`. Why have `waitUntil()` code: ```javascript self.addEventListener('install', function(event) { event.waitUntil(cache.addAll(urls)); }); ``` when code could look like: ```javascript self.addEventListener('install', async function(event) { await cache.addAll(urls); }); ``` and `respondWith()` code: ```javascript self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(response) { return response || fetch(event.request); }) ); }); ``` could be written as: ```javascript self.addEventListener('fetch', async function(event) { let response = await caches.match(event.request); return response || fetch(event.request); }); ``` Being able to use async functions to their full potential as event handlers would lead to code that is a lot easier to read and write. -- 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/1235
Received on Monday, 27 November 2017 05:49:18 UTC