diff --git a/spec/observables/forkJoin-spec.ts b/spec/observables/forkJoin-spec.ts index 896676c034..01afc30b9a 100644 --- a/spec/observables/forkJoin-spec.ts +++ b/spec/observables/forkJoin-spec.ts @@ -263,4 +263,20 @@ describe('Observable.forkJoin', () => { expectObservable(e1).toBe(expected); }); + + it('should allow unsubscribing early and explicitly', () => { + const e1 = hot('--a--^--b--c---d-| '); + const e1subs = '^ ! '; + const e2 = hot('---e-^---f--g---h-|'); + const e2subs = '^ ! '; + const expected = '---------- '; + const unsub = ' ! '; + + const result = Observable.forkJoin(e1, e2); + + expectObservable(result, unsub).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(e2.subscriptions).toBe(e2subs); + }); + }); diff --git a/src/observable/ForkJoinObservable.ts b/src/observable/ForkJoinObservable.ts index 7c8e8a5b7d..a3eccf78f9 100644 --- a/src/observable/ForkJoinObservable.ts +++ b/src/observable/ForkJoinObservable.ts @@ -63,7 +63,8 @@ export class ForkJoinObservable extends Observable { if (isPromise(source)) { source = new PromiseObservable(>source); } - (>source).subscribe(new AllSubscriber(subscriber, i, context)); + subscriber.add((>source) + .subscribe(new AllSubscriber(subscriber, i, context))); } } }