Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@songkick/promise-timeout

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@songkick/promise-timeout

Reject a promise if it does not resolve before specified delay

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

promise-timeout Build Status Code Climate Test Coverage

Reject a promise if it does not resolve before specified delay

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

var hundredMilTimeout = timeoutPromise({delay: 100 });
var boundToReject = hundredMilTimeout(resolvesAfter200);

boundToReject().then(function(result){
  // never called here,
  // but if `delay` was >= 300,
  // result would be === 'yay!'
}).catch(function(err){
  // err instanceof timeoutPromise.TimeoutError === true
  // err === {
  //   message: 'Promise resolution timed out',
  //   settings: {
  //    delay: 100
  //   },
  //   fn: resolvesAfter200
  // }
});

// or if the initial promise rejects before the delay:
//.catch(function(err){
  // err is the original error
//});

function resolvesAfter200() {
  return new Promise(function(resolve, reject){
    setTimeout(resolve, 200)
  });
}

Options

delay: the delay before the promise gets rejected

See also

promise-timeout composes really well with the following promise helper:

Keywords

FAQs

Package last updated on 11 Jan 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc