I am having problems with finalize or complete using the code below. I want to be able to call loading = false after all is done. I tried to use finalize and complete but it is being called too early and multiple times. Any help? Thanks
displayPost(postDetail) {
//some rendering stuff
renderHTML(postDetail);
}
// returns a post query object
getPostQuery(username, postId) {
query: `{
post (id:"${username}", postId:"${postId}") {
id
title
content }`
return query;
}
let loading = true
//getUserHTTP() is an http request
getUserHTTP(userId).pipe(
switchMap(user => {
const ids = [];
// let's say oldest 100 posts
for (let i = 0; i < 100; i++) {
ids.push(getPostQuery(user.username, i))
}
return from(ids);
}),
mergeMap(query => this.httpClient.post(url, query)),
finalize(() => {
//this is being called too early and multiple times
loading = false;
})
).subscribe({
next: result => { /* doing staff */ displayPost(result) },
error: err => { /* handle errors */ },
complete: () => { /* not working */ }
})