request.js
export default (...args) => {
try {
return fetch(...args)
} catch (e) {
return Promise.reject(e);
}
};
fast.js
const TIME_LIMIT = 1000;
const TIME_LIMIT_MESSAGE = 'Out of time limit';
export default p => (...args) => Promise.race([p(...args),new Promise((y,n) => setTimeout(n, TIME_LIMIT, TIME_LIMIT_MESSAGE))]);
FAST_REQUEST.md
Here is example of `fast` implimentation with requests:
```
import fast, request from './';
const {log} = console;
class API {}
API.json = (...args) =>
// @fast request
fast(request)(...args).then(data => data.json());
API.get = url => API.json(url)
(new API()).get('/')
// Success
.then(data => log('ok', {data}))
// Fail
.catch(e => log('nok', {errors:[e]}))
// Finally
.then(() => log('done'));
```