race-timeout-anywhere
A Promise.race timeout function which can be used with any module loader
Last updated 3 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install race-timeout-anywhere 
SYNC missed versions from official npm registry.

view on npm npm module downloads Gihub repo dependents Gihub package dependents Build Status js-standard-style

race-timeout-anywhere

An isomorphic, load-anywhere timeout function for use with Promise.race.

The raceTimeout function never resolves, it will only reject once the specified time period has elapsed. In the example below, fetchDataSomehow() must resolve before raceTimeout rejects after 1000ms, else a timeout exception is thrown.

import raceTimeout from 'race-timeout-anywhere'

try {
  const data = await Promise.race([
    fetchDataSomehow(),
    raceTimeout(1000)
  ])
  /* fetchDataSomehow() took less than 1000ms, process data */
} catch (err) {
  /* fetchDataSomehow() took longer than 1000ms */
}

Load anywhere

This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.

CommonJS:

const raceTimeout = require('race-timeout-anywhere')

ECMAScript Module:

import raceTimeout from 'rice-timeout-anywhere'

Within a modern browser ECMAScript Module:

import raceTimeout from './node_modules/rice-timeout-anywhere/index.mjs'

© 2018-21 Lloyd Brookes <75pound@gmail.com>.

Current Tags

  • 2.0.0                                ...           latest (3 years ago)

5 Versions

  • 2.0.0                                ...           3 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |