JakeChampion / fetch

A window.fetch JavaScript polyfill.

Home Page:http://github.github.io/fetch/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Roy

RoyGila opened this issue · comments

import 'yet-another-abortcontroller-polyfill'
import {fetch} from 'whatwg-fetch'

// use native browser implementation if it supports aborting
const abortableFetch = ('signal' in new Request('')) ? window.fetch : fetch

const controller = new AbortController()

abortableFetch('/avatars', {
signal: controller.signal
}).catch(function(ex) {
if (ex.name === 'AbortError') {
console.log('request aborted')
}
})

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