- From: Ben Kelly <notifications@github.com>
- Date: Wed, 27 Jul 2016 13:46:11 -0700
- To: slightlyoff/ServiceWorker <ServiceWorker@noreply.github.com>
- Message-ID: <slightlyoff/ServiceWorker/issues/935@github.com>
I'm currently implementing async `waitUntil()` in gecko. The main intention here is to allow things like: ``` addEventListener('fetch', e => { e.respondWith(fetch(e.request)).then(response => { e.waitUntil(caches.open('db').then(cache => { return cache.put(e.request, response); }); return response.clone(); }); }); ``` So you can call `waitUntil()` as long as there is an extension promise still unsettled. But what about this non-idiomatic code: ``` addEventListener('fetch', e => { let respondWithPromise = fetch(e.request); respondWithPromise.then(response => { let clone = response.clone(); e.waitUntil(caches.open('db').then(cache => { return cache.put(e.request, clone); }); }); e.respondWith(respondWithPromise); }); ``` Here pass the `fetch()` promise directly to `respondWith()`. Or additional caching code is also hung off this same `fetch()` promise. Technically when the caching code runs the promise passed to `respondWith()` is settled, but if order of promise handlers is maintained then the `respondWith()` code has not been notified yet. I *think* this should probably work, but the spec text is a bit vague. It says: > Wait until the result of waiting for all of extendLifetimePromises settles. Does that respect ordering of promise handlers? Conversely, if we call `respondWith()` before the `respondWithPromise.then()` above, then I think the `waitUntil` should throw. The respondWith code would clear the extensions allowed flag before the caching code had a chance to run. All this is corner casey, but I thought it would be good to clarify. --- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/slightlyoff/ServiceWorker/issues/935
Received on Wednesday, 27 July 2016 20:46:40 UTC