I am working on a simple function that executes 3 asynchronous functions in sequence:
fetchData() {
this.fetchUsers('2')
.pipe(
flatMap((data: any) => {
return this.fetchPosts(data.id);
}),
flatMap((data: any) => {
return this.fetchPosts(data[0].userId);
})
).subscribe(results => {
return new Observable((observer) => {
observer.next(results);
observer.complete();
});
});
}
I am looking for a way to trigger something like:
this.fetchData.subscribe()
once all 3 flatMaps are done. I believe I need to make the fetchData() function return an observable, which I attempted at the end of the code but it's not functioning correctly and I can't call .subscribe on the fetchData() function.