Skip to content

Commit 412b13b

Browse files
trxcllntkwonoj
authored andcommitted
fix(forkJoin): fix forkJoin to complete if sources Array is empty.
1 parent c5ead88 commit 412b13b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spec/observables/forkJoin-spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ describe('Observable.forkJoin', function () {
169169
expectObservable(e1).toBe(expected);
170170
});
171171

172+
it('should complete if sources list is empty', function () {
173+
var e1 = Observable.forkJoin([]);
174+
var expected = '|';
175+
176+
expectObservable(e1).toBe(expected);
177+
});
178+
172179
it('should complete when any of source is empty with selector', function () {
173180
function selector(x, y) {
174181
return x + y;
@@ -242,4 +249,4 @@ describe('Observable.forkJoin', function () {
242249

243250
expectObservable(e1).toBe(expected);
244251
});
245-
});
252+
});

src/observable/forkJoin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export class ForkJoinObservable<T> extends Observable<T> {
2929
sources = <Array<Observable<any>>>sources[0];
3030
}
3131

32+
if (sources.length === 0) {
33+
return new EmptyObservable<T>();
34+
}
35+
3236
return new ForkJoinObservable(<Array<Observable<any> | Promise<any>>>sources, resultSelector);
3337
}
3438

0 commit comments

Comments
 (0)