Re: [whatwg/fetch] Aborting a fetch: The Next Generation (#447)

The following solution works in all browsers.

Include `exec.js` + `exec-fetch.js` (534 + 265 bytes) in the HTML document.

```html
<script src="exec.min.js"></script>
<script src="exec-fetch.min.js"></script>
```

The native [fetch](https://developers.google.com/web/updates/2015/03/introduction-to-fetch) method is now enhanced with a `.cancel()` method.

```javascript
// normal fetch request
var request = fetch('https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js')
    .then(function(response) {
        response.text().then(function(text) {
            console.log('response', text.length);
        });
    }).catch(function(err) {
        console.log('err', err.message);
    });

// cancel after 10ms
setTimeout(function() {
    request.cancel();
}, 10);

```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/447#issuecomment-316129051

Received on Tuesday, 18 July 2017 17:00:49 UTC