Skip to content

Commit

Permalink
First pass at documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesplease committed Dec 8, 2017
1 parent fd5c261 commit a17b192
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,46 @@ response.headers['X-Request-URL'] = request.url
This server workaround is necessary if you need reliable `response.url` in
Firefox < 32, Chrome < 37, Safari, or IE.

#### Aborting requests

This polyfill supports
[the abortable fetch API](https://developers.google.com/web/updates/2017/09/abortable-fetch). However,
aborting a fetch requires use of two additional DOM APIs:
[AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
and [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). Typically,
browsers that do not support fetch will also not support AbortController or AbortSignal.

Consequently, you will need to find a polyfill for these APIs to
abort fetches.

Once you have an AbortController and AbortSignal polyfill in place, you can abort a fetch like
so:

```js
const controller = new AbortController()

fetch('/avatars', {
method: 'POST',
body: data,
signal: controller.signal
})
.then(
function(response) {
console.log('request succeeded', response)
},
function(ex) {
if (ex.name === 'AbortError') {
console.log('request aborted')
} else {
console.log('request failed, but it was not aborted')
}
}
)

// some time later...
controller.abort();
```

## Browser Support

- Chrome
Expand Down

0 comments on commit a17b192

Please sign in to comment.