- From: Jake Archibald <notifications@github.com>
- Date: Tue, 06 Jan 2015 03:09:22 -0800
- To: slightlyoff/ServiceWorker <ServiceWorker@noreply.github.com>
- Message-ID: <slightlyoff/ServiceWorker/issues/592/68853209@github.com>
```js
self.addEventListener('fetch', function(event) {
event.respondWith(
fetch('/whatever.json').then(function(response) {
return response.json();
}).then(function(data) {
return fetch(data.url);
})
);
});
```
We may not have a request to cancel when the user hits the stop button. As far as I know, we can only tie a response to a destination window once the promise passed to `respondWith` resolves, which is when `fetch(data.url)` gets headers.
If the user hits X (or even closes the tab) while `/whatever.json` is fetching, I don't think we can simply cancel the request. We *may* be able to terminate the worker, but only if other tabs aren't using it.
How does this sound? If the request is cancelled from the browser's point of view:
1. That fetch event may no longer keep the SW running, so if no other events are keeping the SW open, the SW may terminate
2. If `respondWith` has been called with a promise that has not resolved, wait for it to resolve
3. If the response given to `respondWith` has a stream, abort it
---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/592#issuecomment-68853209
Received on Tuesday, 6 January 2015 11:09:49 UTC