Socket
Socket
Sign inDemoInstall

time-limit-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    time-limit-promise

Fulfill long runinng promises on timeout.


Version published
Weekly downloads
225K
increased by3.14%
Maintainers
1
Install size
5.11 kB
Created
Weekly downloads
 

Readme

Source

time-limit-promise

Build Status

Fulfill long runinng promises on timeout.

Unlike other implementations on npm it has some nice extra features:

  • You can both reject and resolve promises on timeout
  • You can provide custom value with which promise will be rejected or resolved on timeout
  • Unrefs promise timer, so it will not block your app from exit.
  • Uses Promise implementation of the passed promise: no external implementation dependencies, no global Promise dependencies

Install

npm install time-limit-promise

Usage

const timeLimit = require('time-limit-promise');
const fetch     = require('node-fetch');

var fetchPromise = fetch('https://github.com/inikulin');

timeLimit(fetchPromise, 50).then(res => {
    // If `fetchPromise` will be fulfilled within 50ms
    // time limited promise will be fullfilled as well.
    // Otherwise, it will be resolved with the `undefined` value.
});

timeLimit(fetchPromise, 50, { resolveWith: 'no content' }).then(res => {
    // Same as above, but on timeout it will
    // be resolved with the `no-content` value.
    console.log(res); // > no-content
});


timeLimit(fetchPromise, 50, { rejectWith: new Error('timeout') }).catch(err => {
    // Same as above, but on timeout it will
    // be rejected with the provided error.
    console.log(err.message); // > timeout
});

Author

Ivan Nikulin (ifaaan@gmail.com)

Keywords

FAQs

Last updated on 21 Jun 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