I'm exactly sure what you're asking but.
If you want to run an array of promises sequentially there's this answer
The important thing to note is it's not an array of promises. It's an array of functions that make a promise. That's because promises execute immediately so you can't create the promise until you need it.
If you don't want to put them in array though the normal thing is just chain them normally.
Again the easiest way to to make a bunch functions the return promises. Then you just
var p = firstFunctionThatReturnsAPromise()
.then(secondFunctionThatReturnsAPromise)
.then(thirdFunctionThatReturnsAPromise)
.then(fourthFunctionThatReturnsAPromise)
You can nest them just as easily
function AOuterFunctionThatReturnsAPromise() {
var p = firstFunctionThatReturnsAPromise()
.then(secondFunctionThatReturnsAPromise)
.then(thirdFunctionThatReturnsAPromise)
.then(fourthFunctionThatReturnsAPromise);
return p;
};
Now that outer function is just another function returning a promise which means you
can apply same pattern as the inner functions.
If course those can be inline
var p = function() {
return new Promise(resolve, reject) {
DoSomethingAsync(function(err, result) {
if (err) {
reject();
} else {
resolve(result);
};
};
}).then(function() {
return new Promise(resolve, reject) {
DoSomethingAsync(function(err, result) {
if (err) {
reject(err);
} else {
resolve(result);
};
};
}).then(function() {
var err = DoSomethingNotAsync();
if (err) {
return Promise.reject(err);
} else {
return Promise.resolve();
}
});
etc...