Skip to content

Commit

Permalink
fix(forkJoin): catch and forward selector errors (#3261)
Browse files Browse the repository at this point in the history
* test(forkJoin): add selector error test

* fix(forkJoin): catch and forward selector errors

Closes #3216
  • Loading branch information
cartant authored and benlesh committed Jan 26, 2018
1 parent 99b4937 commit e57bbb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/observables/forkJoin-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ describe('Observable.forkJoin', () => {
expectObservable(e1).toBe(expected);
});

it('should raise error when the selector throws', () => {
function selector(x, y) {
throw 'error';
}

const e1 = Observable.forkJoin(
hot('--a-|'),
hot('---b-|'),
selector);
const expected = '-----#';

expectObservable(e1).toBe(expected);
});

it('should allow unsubscribing early and explicitly', () => {
const e1 = hot('--a--^--b--c---d-| ');
const e1subs = '^ ! ';
Expand Down
8 changes: 7 additions & 1 deletion src/internal/observable/ForkJoinObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ class ForkJoinSubscriber<T> extends OuterSubscriber<T, T> {
}

if (haveValues === len) {
const value = resultSelector ? resultSelector.apply(this, values) : values;
let value: any;
try {
value = resultSelector ? resultSelector.apply(this, values) : values;
} catch (err) {
destination.error(err);
return;
}
destination.next(value);
}

Expand Down

0 comments on commit e57bbb7

Please sign in to comment.