Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/usefulthink/promise-all-recursive

like `Promise.all()`, but for any type and recursive
https://github.com/usefulthink/promise-all-recursive

javascript nodejs promise

Last synced: 14 days ago
JSON representation

like `Promise.all()`, but for any type and recursive

Awesome Lists containing this project

README

        

# promise-all-recursive

> like `Promise.all()`, but for any type and recursive.

returns a promise that resolves when all promises in a recursive object-structure are resolved.

It doesn't try to do anything with rejected promises, so that is up to you.

## installation

npm install promise-all-recursive

## usage

```javascript
const promiseAllRecursive = require('promise-all-recursive');

const object = {
number: 42,
string: 'something',
promise: Promise.resolve('this could have been from the network'),
nested: {
promise: Promise.resolve('...or the filesystem')
},
array: [
1, 2, Promise.resolve(3)
],
deepNested: [
{ anotherPromise: Promise.resolve('sure!') }
]
}

promiseAllRecursive(object)
.then(result => console.log(result));
```

will print:

```javascript
{
number: 42,
string: 'something',
promise: 'this could have been from the network',
nested: {
promise: '...or the filesystem'
},
array: [
1, 2, 3
],
deepNested: [
{ anotherPromise: 'sure!' }
]
}
```

see `test/test.js` for more examples.