Combination in Q

With Q, you have a unique facility in Node.js to write cleaner and manageable code if you want to combine a list of array of promises. This can help you to write a more complex level of sequential data structure in a more manageable way. How can we get there? Use all. Consider the following example:

return Q.all([
    eventAdd(2, 2),
    eventAdd (10, 20)
]);

The Q.all([func1(), func2()]); function will be the generic form of the preceding code. You can also use spread to replace then. Can we replace another new thing with Q? Not really! The spread function spreads the values over the arguments of the fulfillment handler. For the rejection handler, it will get the first signal of failure. So, any of the promises destined to fail first will ...

Get Mastering JavaScript Promises now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.