timeout-r2
`fetch` doesn't time out.
Last updated 2 years ago by patrickleet .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install timeout-r2 
SYNC missed versions from official npm registry.

timeout-request

fetch doesn't time out.

this does.

Great for use with circuit breaker pattern.

import circuitBreaker from 'circuit-breaker-await-async'
import timeoutRequest from 'timeout-request'

let endpoint = 'https://api.com/stuff'
let getStuffFromEndpoint = new CircuitBreaker(
  timeoutRequest({
    method: 'get',
    endpoint,
    timeout: 5 * 1000 // 5s timeout
  }),
  {
    callTimeoutMs: 30 * 1000 // 30s delay between attempts
  }
)

try {
  let stuff = await getStuffFromEndpoint.call()
} catch (error) {
  if (error.message.includes('CIRCUIT_IS_OPEN')) {
    // handle error - this means it failed 10 times in a row
    // with delays between requests
  } else {
    throw error
  }
}

I've only used this for a get request, so will need modifications to support other stuff.

Needed to share it between projects though so I published as is!

Current Tags

  • 1.0.5                                ...           latest (2 years ago)

7 Versions

  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 6
Dependencies (2)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |