Back to Rxjs

This is RxJS v 4. Find the latest version here

doc/api/core/operators/refcount.md

4.1.02.6 KB
Original Source

This is RxJS v 4. Find the latest version here

ConnectableObservable.prototype.refCount()

Returns an observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.

Returns

(Observable): An observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.

Example

js
var interval = Rx.Observable.interval(1000);

var source = interval
    .take(2)
    .doAction(function (x) {
        console.log('Side effect');
    });

var published = source.publish().refCount();

published.subscribe(createObserver('SourceA'));
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
// => Completed

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: