2
votes

I have several observables request. Each observable request is recursive call and when there is no more data, it will call EMPTY.

for example:

request1 = recursive observable call
request2 = recursive observable call
request3 = recursive observable call

Then i use forJoin

forJoin(request, request2, request3).subscribe();

The forkJoin will callback with complete when anyone of them finish. It actually not wait for all observables complete. I check the rxjs document, it mention

When all observables complete, emit the last emitted value from each.

As I don't care these observables return value, so it would not emit value to the forkJoin observer. Then i found that in this case if only one complete, forkJoin observer is notified with complete.

Is this the observable limitation that i do need to emit value to able to wait for all observables complete?

Thanks a lot.

1
It's actually very confusing what behavior you need. forkJoin won't complete unless all source Observable emit at least one value. If one source just completes and doesn't emit anything forkJoin will never complete. - martin
In my testing, forkJoin actually complete when one emit complete. Finally i work around with to emit one value before complete. - rodent_la
You can just return of(true) instead of EMPTY, that will complete the stream with a value. - Fan Cheung

1 Answers

1
votes

It is by design.

Reference here:

forkJoin short circuits if one of the streams completes without emitting a value.

Since EMPTY just emits 'complete' and nothing else, forkJoin will complete right there.

Actually, the other non-empty observables inside forkJoin will still be subscribed, but since forkJoin may complete before them (depends on when did the EMPTY appear in forkJoin), you may not be able to handle them inside the forkJoin's complete function.