Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goto-bus-stop/p-join
combine results from multiple promises into a single value
https://github.com/goto-bus-stop/p-join
promise
Last synced: about 2 months ago
JSON representation
combine results from multiple promises into a single value
- Host: GitHub
- URL: https://github.com/goto-bus-stop/p-join
- Owner: goto-bus-stop
- License: mit
- Created: 2017-06-11T11:21:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-01T11:04:30.000Z (over 3 years ago)
- Last Synced: 2024-11-01T15:38:35.497Z (2 months ago)
- Topics: promise
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# p-join
Combine results from multiple promises into a single value.
Like [Promise.join](http://bluebirdjs.com/docs/api/promise.join.html) from bluebird.
## Installation
With npm:
```bash
npm install --save p-join
```## Usage
```js
var join = require('p-join')var result = join(
Promise.resolve(10),
Promise.resolve(20),
function (a, b) { return a + b }
)result.then(function (sum) {
assert.equal(sum, 30)
})
```Compare doing this with `Promise.all`:
```js
var result = Promise.all([
Promise.resolve(10),
Promise.resolve(20)
]).then(function (results) { return results[0] + results[1] })result.then(function (sum) {
assert.equal(sum, 30)
})
```## API
### result = require('p-join')(...promises, callback)
Pass Promises or values as separate arguments.
The `callback` receives the resolved values of all `...promises` as arguments, in order.
If `callback` returns a value or a Promise, `result` will resolve with that value.## License
[MIT](./LICENSE)