promise-timeout-rejectiondeprecated

reject a promise if it takes more than a set duration

Usage no npm install needed!

<script type="module">
  import promiseTimeoutRejection from 'https://cdn.skypack.dev/promise-timeout-rejection';
</script>

README

promise timeout rejection

NPM version Build status License Code style

Reject a promise if it takes more than a set duration.

Installation

$ npm install --save promise-timeout-rejection

...or:

$ yarn add promise-timeout-rejection

Usage

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