@andycasen/withtimeout
v1.0.0
Published
Allows the use of a timeout on promise based functions like Fetch.
Downloads
3
Maintainers
Readme
@andycasen/withtimeout
Adds a timeout for promise based functions like the fetch API.
Install
$ npm install @andycasen/withtimeout --save
Usage
const fetch = require('node-fetch')
const withTimeout = require('@andycasen/withtimeout')
const myFetchUrl = 'https://myfetchurl.com'
const myTimeout = 3500 // Timeout in ms
withTimeout(fetch(myFetchUrl), myTimeout)
.then(data => data.json())
.then(data => {
// Do something with your data
})