promise-timeout
Simple timeouts for promises
Last updated 3 years ago by leedm777 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install promise-timeout 
SYNC missed versions from official npm registry.

promise-timeout

A super-simple way to put a timeout on promise resolution.

It assumes you already have either platform support for promises (Node 0.12 or greater), or you have a polyfill (see es6-promise).

Installation

$ npm install promise-timeout

Usage

timeout(promise, timeoutMillis)

Rejects a promise with a TimeoutError if it does not settle within the specified timeout. Parameters:

  • promise: Promise - Promise to monitor.
  • timeoutMillis: number - Number of milliseconds to wait on settling.

TimeoutError

Exception indicating that the timeout expired.

Examples

ES2015:

import { timeout, TimeoutError } from 'promise-timeout';

let somePromise = goDoSomething();

timeout(somePromise, 1000)
  .then((thing) => console.log('I did a thing!'))
  .catch((err) => {
    if (err instanceof TimeoutError) {
      console.error('Timeout :-(');
    }
  });

ES5:

'use strict';

var pt = require('promise-timeout');

var somePromise = goDoSomething();

pt.timeout(somePromise, 1000)
  .then(function (thing) {
    console.log('I did a thing!');
  }).catch(function (err) {
    if (err instanceof pt.TimeoutError) {
      console.error('Timeout :-(');
    }
  });

Current Tags

  • 1.3.0                                ...           latest (3 years ago)

5 Versions

  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 2
This Week 430
This Month 2
Last Day 129
Last Week 980
Last Month 4,035
Dependencies (0)
None
Dev Dependencies (1)
Dependents (79)

Copyright 2014 - 2016 © taobao.org |