This is RxJS v 4. Find the latest version here
Returns an observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.
(Observable
): An observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.
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
File:
Dist:
Prerequisites:
- If using
rx.binding.js
NPM Packages:
NuGet Packages:
Unit Tests: