primeout
Create a promise with a timeout.
Last updated 4 years ago by jpwilliams .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install primeout 
SYNC missed versions from official npm registry.

Primeout

Build Status Coverage Status npm downloads per month npm version

Create a promise with a timeout.

npm install primeout
const primeout = require('primeout')

// Will reject if the `connectToDb()` promise does
// not respond within 30 seconds.
primeout('30 seconds', connectToDb()).then((db) => {
  ...
}).catch((err) => {
  ...
})

Contents

Examples

All of these examples assume that connect() returns a promise.

// Set a timeout of 5 seconds
primeout(5000, connect())
  .then(...)
  .catch(...)
// Set a timeout of 5 minutes
primeout('5m', connect())
  .then(...)
  .catch(...)
// Set a timeout that rejects if the
// promise is not resolved or rejected
// before the next event loop.
primeout(0, connect())
  .then(...)
  .catch(...)

For a clear-cut explanation of that last example (especially if you're new to node.js) see Understanding the node.js event loop.

API reference

primeout

The only export from the module. A function used to return the timeout-enabled promise desired.

Arguments
  • time The timeout being specified. Can either be a number specifying the amount of milliseconds or a valid timestring.
  • promise The promise you wish to set a timeout for.

Current Tags

  • 1.1.2                                ...           latest (4 years ago)

4 Versions

  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (1)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |