question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

forkJoin doesn't emit any value for empty array

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
klinkicommented, Jan 30, 2018

@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);
}
1reaction
klinkicommented, Aug 28, 2017

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.)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found