RefCount
make a Connectable Observable behave like an ordinary Observable
See Also
- Connect
- Publish
- Replay
- Introduction to Rx: RefCount
- Wedding Party: Share, Publish, Refcount, and All That Jazz by Kaushik Gopal
Language-Specific Information
RxGroovy refCount share
There is also a share
operator, which is the equivalent of applying both the publish
and refCount
operators to an Observable, in that order.
- Javadoc:
share()
RxJava 1․x refCount share
There is also a share
operator, which is the equivalent of applying both the publish
and refCount
operators to an Observable, in that order.
- Javadoc:
share()
RxJS refCount share shareValue
There is also a share
operator, which is the equivalent of applying both the publish
and refCount
operators to an Observable, in that order. A variant called shareValue
takes as a parameter a single item that it will emit to any subscribers before beginning to emit items from the source Observable.
Sample Code
var interval = Rx.Observable.interval(1000); var source = interval .take(2) .do( function (x) { console.log('Side effect'); }); var published = source.share(); // When the number of observers subscribed to published observable goes from // 0 to 1, we connect to the underlying observable sequence. published.subscribe(createObserver('SourceA')); // When the second subscriber is added, no additional subscriptions are added to the // underlying observable sequence. As a result the operations that result in side // effects are not repeated per subscriber. published.subscribe(createObserver('SourceB')); function createObserver(tag) { return Rx.Observer.create( function (x) { console.log('Next: ' + tag + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); }); }
Side effect Next: SourceA0 Next: SourceB0 Side effect Next: SourceA1 Next: SourceB1 Completed
share
and shareValue
are found in the following distributions:
rx.all.js
rx.all.compat.js
-
rx.binding.js
(requiresrx.js
orrx.compat.js
) rx.lite.js
rx.lite.compat.js
RxPHP share singleInstance shareValue
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/refcount.html