Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arpitgo4/promise-obj
Promise.all's implementation for objects.
https://github.com/arpitgo4/promise-obj
async chai chai-as-promised mocha nodejs npm-package promise tdd
Last synced: 25 days ago
JSON representation
Promise.all's implementation for objects.
- Host: GitHub
- URL: https://github.com/arpitgo4/promise-obj
- Owner: arpitgo4
- License: gpl-3.0
- Created: 2019-05-16T08:17:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-21T13:26:56.000Z (over 5 years ago)
- Last Synced: 2024-10-01T14:57:20.769Z (about 1 month ago)
- Topics: async, chai, chai-as-promised, mocha, nodejs, npm-package, promise, tdd
- Language: JavaScript
- Size: 61.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Promise.all for objects
Resolves an object containing deeply nested promises in sub-objects and arrays.
It internally uses Promise.all for concurrent resolution of promises.### To Install
```
npm install --save @arpitgo4/promise-obj
```### How to use ?
#### Promise resolution
```javascript
const promise-obj = require('@arpitgo4/promise-obj');const p3 = Promise.resolve(3);
const p5 = Promise.resolve(5);
const p7 = Promise.resolve(7);
const p9 = Promise.resolve(9);
const p10 = Promise.resolve(10);
const p12 = Promise.resolve(12);
const p13 = Promise.resolve(13);
const p15 = Promise.resolve(15);
const p16 = Promise.resolve(16);const test_obj = {
one: 1,
two: {
three: p3,
four: {
five: p5,
six: {
seven: p7,
eight: [ 8, p9, ],
},
}
},
ten: [ p10, 11, p12, { thirteen: p13, fourteen: { fifteen: p15 } }, { sixteen: p16 } ],
};return promise-obj(test_obj)
.then(result_obj => console.log(result_obj))
.catch(err => console.error(err));// result_obj:
// {
// one: 1,
// two: {
// three: 3,
// four: {
// five: 5,
// six: {
// seven: 7,
// eight: [ 8, 9, ],
// },
// }
// },
// ten: [ 10, 11, 12, { thirteen: 13, fourteen: { fifteen: 15 } }, { sixteen: 16 } ],
// }```
#### Promise rejection
Promise will reject if any of the nested promises fails, same as Promise.all.```javascript
const error = new Error('some error!');
const test_obj = {
one: 1,
two: Promise.reject(error),
three: 3,
};return promise-obj(test_obj)
.catch(error => console.log(error)); // some error!
```### How to contribute
```
## run mocha in watch mode
npm run test:watch
```