- From: Asa Kusuma <notifications@github.com>
- Date: Fri, 23 Mar 2018 21:37:05 +0000 (UTC)
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1292@github.com>
It looks like the idea has [already been brought up](https://github.com/w3c/ServiceWorker/issues/980#issuecomment-314487339) and is [already implemented](https://github.com/w3c/ServiceWorker/issues/1182) in some fashion in at least FF and chrome, but it would be nice is there was some spec guarantee on guarding async operations with a timeout, and some way to customize behavior. In theory, it's not hard to create a service worker than can never be removed, by creating some aysnc operation that can never finish: ```JavaScript e.waitUntil(new Promise(() => {})); ``` ```JavaScript addEventListener('install', (e) => { e.waitUntil(registration.unregister()); }); ``` A few ideas for public APIs to prevent these issues and provide fine-grain control: #### Additional timeout param for `waitUntil`/`respondWith` ```JavaScript // Abort if promise doesn't resolve within 5 seconds. e.waitUntil(new Promise(() => {}), { timeout: 5000 }); ``` #### API for adding a default timeout for functional events Not quite sure where this could be done. Perhaps during worker registration? I feel like adding a worker specific option to `addEventListener` would be too intrusive. #### Allow installing worker to cutoff active worker Specifically, allow `skipWaiting` to provide an “ultimatum” timeout to the active worker to finish any async operations. ```JavaScript // Give the active worker 5 seconds to terminate any operations before killing self.skipWaiting({ gracePeriod: 5000 }); ``` -- 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/1292
Received on Friday, 23 March 2018 21:37:35 UTC