RxJS version:
5.3.0
Code to reproduce:
Rx.Observable.forkJoin([]).subscribe(data => console.log(data));
Expected behavior:
Code should return empty array.
Actual behavior:
Subscribe is never called.
Additional information:
I think emitting empty array is better, then not emitting at all. User code using forkJoin could handle those situations (for example it might show some message to user).
Also if valid input is array of Observables and output is array of resolved values, then, it should handle situations with empty input array. And I believe empty output array is perfectly valid solution for that.
Closing as dupe of https://github.com/ReactiveX/rxjs/issues/2188#issuecomment-266521238. Forkjoin is intentionally designed to be used for cases where all observable should emit values. Current behavior is expected. When there is any source doesn't emit, forkjoin 'completes' immediately - that's operator's indication.
I don't see how it is dupe of that comment. Also for empty array, you don't have any Observables at all.
When there is any source doesn't emit, forkjoin 'completes' immediately - that's operator's indication.
I'm sorry, I don't understand this.
It is dupe. Forkjoin doesn't consider any other case except all sources emits value, so empty array is also short-curcuit to completion immediately.
In your snippet, you've supplied observer::next only (subscribe(data => console.log(data))) and saying subscribe is never called - but subscribe is actually called in there.
Rx.Observable.forkJoin([]).subscribe(data => console.log(data), null, () => console.log('completed'));
//`completed`
when forkJoin short curcuits, it gives observer::complete immediately without giving signal to observer::next.
I see. Thanks for explanation.
I'm not sure if it is the right way, but I understand your reasoning. I will create custom wrapper for it.
(I need it to call observer::next even for empty array, because I don't control what is on input - there could be array of Observables, but in certain cases, it could be also empty array.)
how you use observer::next @klinki ?
@Assdi Actally, I do initial array check, to see if it is not an empty array. And if it is, I don't use forkJoin at all.
Example:
if (observablesArray.length === 0) {
return Observable.of([]);
} else {
return Observable.forkJoin(observablesArray);
}
thanks for ur time :+1: @KevinMcIntyre i did it already
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@Assdi Actally, I do initial array check, to see if it is not an empty array. And if it is, I don't use
forkJoinat all.Example: