Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Rx.Observable.forkJoin with empty list as parameter not calling complete #1506

Open
airiciuc opened this issue Aug 18, 2017 · 2 comments
Open

Comments

@airiciuc
Copy link

airiciuc commented Aug 18, 2017

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:

  1. processUpdate function is never called
  2. onUpdatesFinished is called once

Actual behavior:

  1. processUpdate function is never called
  2. 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

@airiciuc
Copy link
Author

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 {
			...
		}
	});

@ManuelSch
Copy link

I've got the same issue (using a map function returning a potentially empty array).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants