Skip to content

Commit c7bf30c

Browse files
trxcllntkwonoj
authored andcommitted
fix(forkJoin): dispose the inner subscriptions when the outer subscription is disposed
1 parent 2a1796a commit c7bf30c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

spec/observables/forkJoin-spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,20 @@ describe('Observable.forkJoin', () => {
263263

264264
expectObservable(e1).toBe(expected);
265265
});
266+
267+
it('should allow unsubscribing early and explicitly', () => {
268+
const e1 = hot('--a--^--b--c---d-| ');
269+
const e1subs = '^ ! ';
270+
const e2 = hot('---e-^---f--g---h-|');
271+
const e2subs = '^ ! ';
272+
const expected = '---------- ';
273+
const unsub = ' ! ';
274+
275+
const result = Observable.forkJoin(e1, e2);
276+
277+
expectObservable(result, unsub).toBe(expected);
278+
expectSubscriptions(e1.subscriptions).toBe(e1subs);
279+
expectSubscriptions(e2.subscriptions).toBe(e2subs);
280+
});
281+
266282
});

src/observable/ForkJoinObservable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class ForkJoinObservable<T> extends Observable<T> {
6363
if (isPromise(source)) {
6464
source = new PromiseObservable(<Promise<any>>source);
6565
}
66-
(<Observable<any>>source).subscribe(new AllSubscriber(subscriber, i, context));
66+
subscriber.add((<Observable<any>>source)
67+
.subscribe(new AllSubscriber(subscriber, i, context)));
6768
}
6869
}
6970
}

0 commit comments

Comments
 (0)