robinpowered / react-native-fetch-polyfill

Exposes options to React Native's XMLHttpRequest that are not accessible by `whatwg-fetch`
72 stars 23 forks source link

Fetch timeout polyfill #1

Closed atticoos closed 7 years ago

atticoos commented 7 years ago

Adds support for fetch to respect a timeout value.

fetch(url, {...options, timeout: 30 * 1000})

See the README for a description of how this works and how it will be maintained.

TL;DR

Networking on the JS side is all done through a library called fetch (specification). fetch is an abstraction on top of XMLHttpRequest, which is a browser API for networking.

React Native implements the XMLHttpRequest API with a backing native networking module, RCTNetworking (interfaced by an ios and android JS file).

This supports all the bells and whistles for timeouts and aborting requests, the problem is that the the fetch specification doesn't describe a standard for aborting and timing out requests.

The polyfill allows the timeout to reach the underlying XMLHttpRequest instance.