New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

impatient

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

impatient

A tool for turning asynchronous things into impatient versions of themselves

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

impatient

NPM version Build Status

A tool for turning asynchronous things into impatient versions of themselves

Install

npm installimpatient

Usage

var impatient = require('impatient');
var sleep = require('sleep-promise');

// impatient promise (wait for 1000ms but reject at 50ms)
impatient(sleep(1000), 50 /* max patience */).catch(function(err) {
  console.error('promise rejection', err); // timeout error
});

// impatient callback (wait for 1000ms but give up at 50ms)
var impatientCb = impatient(function(cb) { setTimeout(cb, 1000); }, 50 /*max patience*/);

impatientCb(function(err) {
  console.error('callback error', err); // timeout error
});

If you want to perform some cleanup on aborting, you may pass in a function as the 3rd param to impatient.

impatient(sleep(1000), 50, function() {
  console.log('cleanup');
  // return optional promise, which will delay the resolution till cleanup is done
}).catch(function(err) {
  // cancels the wait with Error('timeout')
  console.error(err);
});

var impatientCb = impatient(function(cb) { setTimeout(cb, 1000); }, 50, function(cb) {
  console.log('cleaning up cb');
  cb();
});

impatientCb(function(err) {
  console.error('callback error', err);
});

License

MIT © Allain Lalonde

Keywords

promise

FAQs

Package last updated on 18 Oct 2015

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