Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allain/impatient
A tool for turning asynchronous things into impatient versions of themselves
https://github.com/allain/impatient
Last synced: 4 days ago
JSON representation
A tool for turning asynchronous things into impatient versions of themselves
- Host: GitHub
- URL: https://github.com/allain/impatient
- Owner: allain
- License: other
- Created: 2015-10-17T19:09:50.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-18T19:55:53.000Z (over 9 years ago)
- Last Synced: 2024-12-21T02:41:35.257Z (28 days ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# impatient
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]> A tool for turning asynchronous things into impatient versions of themselves
## Install
```bash
npm installimpatient
```## Usage
```js
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.
```js
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](http://github.com/allain)
[npm-url]: https://npmjs.org/package/impatient
[npm-image]: https://img.shields.io/npm/v/impatient.svg?style=flat-square[travis-url]: https://travis-ci.org/allain/impatient
[travis-image]: https://img.shields.io/travis/allain/impatient.svg?style=flat-square