Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allain/node-promise-hopeful
A module that catches rejected promises and resolves them with Errors
https://github.com/allain/node-promise-hopeful
Last synced: 4 days ago
JSON representation
A module that catches rejected promises and resolves them with Errors
- Host: GitHub
- URL: https://github.com/allain/node-promise-hopeful
- Owner: allain
- License: isc
- Created: 2015-01-19T13:41:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-19T19:12:07.000Z (almost 10 years ago)
- Last Synced: 2024-12-21T02:41:34.325Z (28 days ago)
- Language: JavaScript
- Homepage:
- Size: 141 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# promise-hopeful
A module that catches rejected promises and resolves them with Errors.
It's useful when you want to run Promise.all and have it resolve all promise resolutions.
[![build status](https://secure.travis-ci.org/allain/node-promise-hopeful.png)](http://travis-ci.org/allain/node-promise-hopeful)
## Installation
This module is installed via npm:
``` bash
$ npm install promise-hopeful
```## Example Usage
``` js
var hopeful = require('promise-hopeful');
var assert = require('assert');// creation of error object
hopeful(Promise.reject()).then(function(result) {
assert(result instanceof Error);
});// passthrough of rejected value
hopeful(Promise.reject('baaaah')).then(function(result) {
console.log(result.message); //=> baaaah
});// passthrouh of error
hopeful(Promise.reject(new Error('failure'))).then(function(result) {
assert(result instanceof Error);
});// Resolves normally
hopeful(Promise.resolve('hello')).then(function(result) {
console.log(result); //=> hello
});```