forkJoin doesn't emit any value for empty array
See original GitHub issueRxJS 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.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
RxJs - forkJoin with empty array - Stack Overflow
That's because forkJoin requires all source Observables to emit at least one item and when there are no source Observables there's nothing ...
Read more >forkJoin - RxJS
forkJoin is an operator that takes any number of input observables which can be passed either as an array or a dictionary of...
Read more >[Solved]-RxJs - forkJoin with empty array-rx.js
That's because forkJoin requires all source Observables to emit at least one item and when there are no source Observables there's nothing to...
Read more >ForkJoin behavior on empty input - MSDN - Microsoft
It actually blocks indefinitely as soon as any of the source observables complete without producing a value. I'm not sure whether the behavior ......
Read more >forkJoin - Learn RxJS
⚠ If an inner observable does not complete forkJoin will never emit a value! Why use forkJoin ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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:
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.)