У меня есть несколько вызовов api, в которых зависит от другого вызова. Как я могу добиться этого с помощью rxjs?



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


this.serviceInst.firstAPIMethod()
.flatMap(firstMethodResult => this.serviceInst.secondAPIMethod(firstMethodResult))
.flatMap(secondMethodResult => this.serviceInst.thirdAPIMethod(secondMethodResult))
.subscribe(thirdMethodResult => {
console.info(thirdMethodResult);
});
let inSequence = (tasks) => { // tasks being an array of functions returning promises
return tasks.reduce((p, task) => p.then(task), Promise.resolve());
}
inSequence(tasks).then(() => {
console.info('all requests done');
});
попробуйте это образец