Skip to content

Latest commit

 

History

History
75 lines (59 loc) · 3.12 KB

multicast.md

File metadata and controls

75 lines (59 loc) · 3.12 KB

Rx.Observable.prototype.multicast(subject | subjectSelector, [selector])

Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's invocation. For specializations with fixed subject types, see publish, share, publishValue, shareValue, publishLast, replay, and shareReplay.

Arguments

  1. subjectSelector (Function): Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function.
  2. subject (Subject): Subject to push source elements into.
  3. [selector] (Function): Optional selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if subjectSelector is provided.

Returns

(Observable): An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.

Example

var subject = new Rx.Subject();
var source = Rx.Observable.range(0, 3)
    .multicast(subject);

var observer = Rx.Observer.create(
    function (x) {
        console.log('Next: ' + x);
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    }
);

var subscription = source.subscribe(observer);
subject.subscribe(observer);

var connected = source.connect();

subscription.dispose();

// => Next: 0
// => Next: 0
// => Next: 1
// => Next: 1
// => Next: 2
// => Next: 2
// => Completed

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: