1.0.5 • Published 9 years ago
promise-timeout-rejection v1.0.5
promise timeout rejection
Reject a promise if it takes more than a set duration.
Installation
$ npm install --save promise-timeout-rejection...or:
$ yarn add promise-timeout-rejectionUsage
Wrap a promise and define a timeout in milliseconds. If the promise resolves or rejects in that time then it acts in the exact same way as
the original promise, otherwise it's rejected with a specific PromiseTimeOutError error.
promiseTimeout(promise, timeout)
const promiseTimeout = require('promise-timeout-rejection')
const pausePromise = require('pause-promise')
// `pausePromise` takes an argument of the amount of milliseconds
// it will take to resolve
promiseTimeout(pause(1500), 2000)
  .catch(err => {
    assert(err instanceof promiseTimeout.PromiseTimeOutError)
  })