I have an array of observables which i want to execute in order, ie wait for one request to complete before the next.
If i use forkJoin, the requests are executed in parallel and i can use it like,
forkjoin(arrayOfObservables)
What is the equivalent way to use concatMap with array of observables. I want something like
concatMap(arrayOfObservables)
Example:
booleanQuestion$ = (question) => {
return this.assessmentService
.createBooleanQuestion(this.testId, question)
.pipe(
tap(
(res) => {
this.questionsCreated += 1;
this.progress =
(this.questionsCreated / this.questions.length) * 100;
},
(err) => console.log(err)
)
);
};
pushBooleanQuestions(): Array<Observable<any>> {
const booleanQuestions$ = [];
this.booleanQuestions.forEach((questionObj) => {
questionObj.order = this.elements.findIndex(
(element) => element.component === questionObj.component
);
delete questionObj.component;
booleanQuestions$.push(this.booleanQuestion$(questionObj));
});
return booleanQuestions$;
}
let allQuestions = this.pushBooleanQuestions()
.concat(this.pushSubjectiveQuestions())
.concat(this.pushObjectiveQuestions());
this.questionCreation$ = forkJoin(allQuestions);
I want to subscribe to this.questionCreation$. It should be using concatMap instead of forkJoin.