Unsubscribing to rxjs observable using takeUntil and combineLatest not working

ElliotSchmelliot

I am using the accepted pattern for unsubscribing my Subscriptions:

private ngUnsubscribe: Subject<void> = new Subject();

ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
}

However, I am having issues with the following rxjs code using takeUntil and combineLatest:

this.observableA$.pipe(
    takeUntil(this.ngUnsubscribe),
    combineLatest(
        this.observableB$,
        this.observableC$
    )
).subscribe(([A, B, C]) => {
    // do some work   
})

This subscription seems to be persisting, as I can see the code firing multiple times after the component is destroyed and re-initialized. Any help would be greatly appreciated.

Joshua Chan

Your inner observableB and observableC aren't unsubscribed. Try rearranging your operators:

combineLatest(
    this.observableB$,
    this.observableC$
),
takeUntil(this.ngUnsubscribe)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Immediately unsubscribing from RxJS Observable

combineLatest reset observable - Rxjs

cancelling a observable with takeUntil not working

rxjs combineLatest not working as expected

How to supply an Rxjs observable as data for a method using combineLatest in Jasmine

Rxjs combinelatest observable value is undefined

How to use combineLatest and takeUntil rxjs operators in Angular 5

What alternatives are there to takeUntil with redux-observable and RxJS

rxjs takeuntil, check until observable source is valid

RxJS combineLatest add timer to only one observable

Using RxJS combineLatest to filter observables?

Using RxJS CombineLatest with searching or selection

Retain the type of mutiple Observable<T> using combineLatest() from rxjs under Angular?

Rxjs: Observable.combineLatest vs Observable.forkJoin

normalising data with combineLatest not working as expected on Angular, RxJS

Angular RxJS Observable: takeUntil vs. unsubscribe with a Subscription

Rxjs: Observable with takeUntil(timer) keeps emitting after the timer has ticked

Import of Observable rxjs/Observable is not working

RxJS observable concat not working

rxjs combineLatest and Anguar2 change detection on Observable Arrays

RxJS Observable with Subject, polling via timer and combineLatest does not fire

RXJS 6.3.3 Ionic TypeError: Observable.combineLatest is not a function

Using an rxjs Observable with firestore

RXJS - Observable.do is not working

RxJS observable of array not working as expected

RxJS: using repeat after takeUntil creates a subscription leak

In rxjs, how to unsubscribe from "inner" "interval" observables using takeUntil or takeWhile

How do I prematurely terminate an observable chain using TakeUntil?

Angular 6 Prevent memory leaks multiple Observable in a component using takeUntil