Sequences in Q

Like chaining, sequences is another way to stage your result in the way you want. Sequence is the way you can use in a predefined manner to get the outcome of the situation as desired. To hold it more tightly and to generate the result, Q provides sequences in a unique way.

Suppose you have a number of promise-generating functions, all of them need to be run in a sequence. You can do it manually like this example:

return seq(startValue).then(secondValue).then(thirdValue);

You have to make sure that every then() must be in a sequence with another then(); to maintain the sequence. Failing to do so will break the sequence, and you will not be able to get another value later.

The other way is to instruct your sequence dynamically. This ...

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.