While I m working on a project using angular and RxJs like a charme, I got a wise question to my self.
When we define some observables and chain then in rxjs by a reactive fashion, let say
clickEventA = new Subject();
clickEventB = new Subject();
a$ = this.clickEventA.asObservable().pipe(tap(_ => console.log('you clicked A')));
b$ = this.clickEventB.asObservable().pipe(tap(_ => console.log('you clicked B')));
c$ = combineLatest([this.a$,this.b$]).pipe(
tap( v => console.log(v))
)
So my question in a simple way, I didnt subscribe to any stream here, I dont want to !!! in this case what is RxJs doing under the hood.
how much data is stored, is having observables that are getting not that much events performance freindly? what happens after the last emission !!??
I m new to reactive programming and RxJs
CodePudding user response:
So my question in a simple way, I didnt subscribe to any stream here, I dont want to !!! in this case what is RxJs doing under the hood.
For your example its just instantiate the data-structures
how much data is stored
how much ever it takes to represent the datastructures in memory.
is having observables that are getting not that much events performance freindly?
what are your measurements for performance? speed? memory usage? Observables are might slower than a promise and might consume more memory
what happens after the last emission !!??
For your example? Nothing! There is no emmision. If there would have been an emmission and all subscribers would unsubscribe correctly, then there would be only the initalized data structures around, which the garbagecollecter would take care of.