Socket
Socket
Sign inDemoInstall

promise-timeout

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    promise-timeout

Simple timeouts for promises


Version published
Weekly downloads
183K
increased by5.41%
Maintainers
1
Install size
6.93 kB
Created
Weekly downloads
 

Changelog

Source

v1.3.0 (2018-02-18)

  • #3 - Make promise-timeout more portable

Readme

Source

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 :-(');
    }
  });

Keywords

FAQs

Last updated on 18 Feb 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc