I am facing a scenario where I have an array of values that need to be processed sequentially using observables in RxJS.
Is there a more optimized way to achieve this instead of using nested subscriptions?
let num = 0;
let myObs = new Observable(observe => {
observe.next(1);
})
let content=['x','y','z'];
myObs.subscribe(data => {
let i = 0;
let self = this;
let inlineFunction = function(){
if (i < content.length){
self.generate(num).subscribe(() => {
i++;
inlineFunction();
});
}else{
observer.next(doc);
}
};
inlineFunction();
});
generate(num:number) : Observable < any >{
return num*num;
},