Suppose I have two asynchronous functions, A and B, which are independent to each other.
What I am trying to do is that execute these functions sequentially multiple time as shown below
A -> B -> A -> B -> A -> ...
B waits until A finishes and vice versa.
The following is what I have done so far and I know it is not going to work the way I want.
function A() {
var promise = new Promise...
...
return promise;
}
function B() {
var promise = new Promise...
...
return promise;
}
for(var i=0; i<200; i++) {
var p1 = A();
p1.then(() => {
var p2 = B();
// ----
}
}
How should I change the code?