#1506·RxJS

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

Author: airiciucCreated Aug 18, 2017Updated Mar 2, 2018

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

Source: Reactive-Extensions/RxJS