Skip to content Skip to sidebar Skip to footer

Rxjs Execute The Handler Only Once

I have two observable that I am listening too with the merge operator when one of them is fire, or both I need to execute the handler only once, How can I do this with rx? var sour

Solution 1:

You can use selector function of multicast

Optional selector function that can use the multicasted source stream as many times as needed, without causing multiple subscriptions to the source stream. Subscribers to the given source will receive all notifications of the source from the time of the subscription forward.

http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-multicast

functionfactory() {
   returnnewRx.Subject();
 }

 source.multicast(factory, function(shared) {
   return shared.take(1).do(x=>console.log(x)).concat(shared);
 })
 .subscribe();

Post a Comment for "Rxjs Execute The Handler Only Once"