1.0.0 • Published 5 years ago

@andycasen/withtimeout v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

@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
    })