-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forkJoin doesn't emit any value for empty array #2816
Comments
Closing as dupe of #2188 (comment). 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
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 Rx.Observable.forkJoin([]).subscribe(data => console.log(data), null, () => console.log('completed'));
//`completed` when forkJoin short curcuits, it gives |
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. |
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 Example: if (observablesArray.length === 0) {
return Observable.of([]);
} else {
return Observable.forkJoin(observablesArray);
} |
thanks for ur time 👍 @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. |
RxJS version:
5.3.0
Code to reproduce:
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.The text was updated successfully, but these errors were encountered: