Bluebird missing docs
Blue bird is a great library of promise for front end (angular) and backend (node). But its documentation is definitely not good. Let's list and explain shorty the difference between each useful functions this library provide.
Promise Concepts
Sequential or Parallel processing
Sequential processing means each promises is processed one after the other. Could be useful if you want to have a control on the flow of processing. Or if you need the result of previous promise to process the next.
Parallel processing means the promises are processed at the same time. You cannot guaranty that the order will be preserved.
2 anti patterns not to fall in
Creating an explicit promise that wrap an already promise http://bluebirdjs.com/docs/anti-patterns.html#the-explicit-construction-anti-pattern
http://bluebirdjs.com/docs/anti-patterns.html#the-explicit-construction-anti-pattern
then((success) => { }, error=> { })instead of
```js then(() => {
}) .catch(() => {
})
## Useful bluebird function
* **Promise.all**
- Params: Array of promise
- Process in parallel
- Reject early if an error occur
- the return value is an array of each promises return in the order they were define
* **Promise.each**
Same than promise.all but
- Process in sequence
* **Promise.join**
It is recommended to use Promise.join instead or Promise.all
when the action to do are fixed in advance and not numerous.
In this case only 3 promises that we know in advance.
```js
var Promise = require("bluebird");
var join = Promise.join;
join(getPictures(), getComments(), getTweets(),
function(pictures, comments, tweets) {
console.log("in total: " + pictures.length + comments.length + tweets.length);
});The same that lodash _.some but with promises and with the count parameter that allow to tell the minimal promises that need to be fulfilled before
Example of the doc log only the 2 fastest server to respond.
Use the properties of an object to define promise to be performed. The advantage is that the result is accessible with the same properties name that the input object. Giving the benefit of the spread() operator (instead of the then())
cancel() Cancel a promise if it has not been received already
spread() The result of promise.all is an array of promises returns, but what if you want to define them as parameters ?
Allow doing something globally when error occurred
[isFullfilled](http://bluebirdjs.com/docs/api/isfulfilled.html)
test if the promise is fulfilled
Last updated
Was this helpful?