@andycasen/withtimeout

Allows the use of a timeout on promise based functions like Fetch.

Usage no npm install needed!

<script type="module">
  import andycasenWithtimeout from 'https://cdn.skypack.dev/@andycasen/withtimeout';
</script>

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