You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.
Assume the following scenario where you need a dynamic number of server calls (sometime is 0) and you need to execute some functionality when all of them are done.
let updatesObservable = getRequiredUpdates();
Rx.Observable.forkJoin(...updatesObservable)
.subscribe(() => onUpdatesFinished());
function getRequiredUpdates() {
//dinamically calculate the required updates and return a list of Observables for each ajax call
return [].map(v => Rx.Observable.return(v).map(u => processUpdate(u)));
}
function processUpdate(u) {
//process each update
console.log(u);
}
function onUpdatesFinished() {
//do here some important stuff when all updates finished
console.log("All updates done");
}
Expected behavior:
processUpdate function is never called
onUpdatesFinished is called once
Actual behavior:
processUpdate function is never called
onUpdatesFinished is nerver called
Note: Change return [].map(v => Rx.Observable.return(v).map(u => processUpdate(u))); to return [1, 2, 3].map(v => Rx.Observable.return(v).map(u => processUpdate(u))); and onUpdatesFinished is called once
The text was updated successfully, but these errors were encountered:
Anyone watching this issue? I've hit this again and it's causing bugs so easily.
Here is a simpler situation:
userSearchTemObserver
.flatMap((term) => userService.searchUsers(term))
.mergeMap((users) => Observable.forkJoin(users.map((user) => facebookService.getProfile(user))))
.subscribe((users) => {
if(!users.length) {
//here i want to handle the special case when no user found mathing the search term
//but the it will never get here because forkJoin doesn't emit if the users list is empty
....
} else {
...
}
});
Assume the following scenario where you need a dynamic number of server calls (sometime is 0) and you need to execute some functionality when all of them are done.
Expected behavior:
processUpdate
function is never calledonUpdatesFinished
is called onceActual behavior:
processUpdate
function is never calledonUpdatesFinished
is nerver calledNote: Change
return [].map(v => Rx.Observable.return(v).map(u => processUpdate(u)));
toreturn [1, 2, 3].map(v => Rx.Observable.return(v).map(u => processUpdate(u)));
andonUpdatesFinished
is called onceThe text was updated successfully, but these errors were encountered: