- From: Jake Archibald <notifications@github.com>
- Date: Fri, 20 Feb 2015 02:30:26 -0800
- To: slightlyoff/ServiceWorker <ServiceWorker@noreply.github.com>
- Message-ID: <slightlyoff/ServiceWorker/issues/625/75217729@github.com>
@domenic I'm trying to figure out how this works, but I find the ES6 heavy going. Can you clear up a few things? Firstly, is this how it should work? ```js var p = fetch(url); p.abort(); // aborts fetch for url var p = fetch(url).then(r => r.json()); p.abort(); // aborts fetch for url and rejects promise so .json is never called // or if fetch already resolved: // terminate the stream and reject .json() var p = fetch(url1).then(_ => fetch(url2)); p.abort(); // aborts fetch for url1 and rejects promise so url2 is never fetched // or if fetch(url1) already resolved: // terminate the stream for url1 // abort the fetch for url2 var p = fetch(url1).then(_ => wait(3000)).then(_ => fetch(url2)); // aborts fetch for url1 and rejects // or if fetch(url1) already resolved: // terminate the stream for url1 // reject the 'wait' so url2 never fetches // or if wait(3000) already resolved: // terminate the stream for url1 // abort the fetch for url2 var p = Promise.resolve(fetch(url)); p.abort(); // undefined is not a function (fetchPromise has been casted to a normal promise) ``` If the above is right, we need a generic `AbortablePromise`, then a hook on that for specific abort steps which `FetchPromise` would extend. ```js var p = fetchPromise.then(_ => "Hello"); ``` For the above to work, `.then()` needs to add state (or an onabort callback) to the new promise to maintain the link back to the original fetch. This cannot be done with `@@species` since that's on the `this` object's constructor. If `@@species` was first checked on the `this` object, it could maintain state that way. I imagine I'm missing a simpler way. --- Reply to this email directly or view it on GitHub: https://github.com/slightlyoff/ServiceWorker/issues/625#issuecomment-75217729
Received on Friday, 20 February 2015 10:30:54 UTC