https://github.com/yabab-dev/promise-utils
Promise useful functions
https://github.com/yabab-dev/promise-utils
all progress promise props series
Last synced: 6 months ago
JSON representation
Promise useful functions
- Host: GitHub
- URL: https://github.com/yabab-dev/promise-utils
- Owner: yabab-dev
- License: wtfpl
- Created: 2017-02-10T19:39:28.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-08T16:31:44.000Z (almost 9 years ago)
- Last Synced: 2025-05-27T09:11:36.868Z (8 months ago)
- Topics: all, progress, promise, props, series
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PromiseUtils
Some useful functions for promises
**Install :**
`npm install @chymz/promise-utils`
## Progress callback
When you call `all()`, `props()`, `series()` or `seriesProps()` returned promise
have an available `progress()` method to listen progress of promises executions
**Usage :**
```javascript
import PromiseUtils from '@chymz/promise-utils';
PromiseUtils.all([
promise(),
promise(),
promise()
])
.progress((current, total) => {
let percent = current / total * 100;
})
.then(results => {
// ...
})
```
## `props()`
Instead of using an array with `Promise.all()` you can pass an object to
`PromiseUtils.props()`
**Usage :**
```javascript
import PromiseUtils from '@chymz/promise-utils';
PromiseUtils.props({
one: promise(),
two: promise()
})
.then(results => {
/*
results object is like :
{
one: 'result of first promise',
two: 'result of second promise'
}
*/
})
```
## `series()`
@todo : description (see `tests/index.js`)
## `seriesProps()`
@todo : description (see `tests/index.js`)
## Override Promise class used by this lib
If you don't want to use native Promise class, you can do this :
```javascript
import Bluebird from 'bluebird';
import PromiseUtils from 'promise-utils';
PromiseUtils.Promise = Bluebird;
// or simply :
global.Promise = Bluebird;
```
## Todo
- Polyfill note for IE11 & Old browsers
- `series()` & `seriesProps()` description/samples
## License
See `LICENSE` file