rxjs - Does a Subject safely unsubscribe its subscribers when it completes? -


if have class subject emits single value during life:

export class myclass {   myemitter$: subject<void> = new subject();    somemethod(){     this.myemitter$.next();     this.myemitter$.complete();   } } 

and in class:

this.instanceofmyclass.myemitter.subscribe(); 

should unsubscribe instanceofmyclass.myemitter$, given subject completes after emitting?

when call complete on subject, subscribers automatically unsubscribed.

if @ source subject's complete method:

complete() {   if (this.closed) {     throw new objectunsubscribederror();   }   this.isstopped = true;   const { observers } = this;   const len = observers.length;   const copy = observers.slice();   (let = 0; < len; i++) {     copy[i].complete();   }   this.observers.length = 0; } 

you'll see subject calls complete on each of observers. , observable contract states that:

when observable issues [error] or [complete] notification observers, ends subscription. observers not need issue [unsubscribe] notification end subscriptions ended observable in way.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -