Home » RxJS share() Multicasting Operator

RxJS share() Multicasting Operator

by Online Tutorials Library

RxJS share() Multicasting Operator

RxJS share() operator is a multicasting operator which returns a new observable that shares or multicasts the original observable. As long as there is at least one subscriber, this observable will be subscribed and emitting data. When all subscribers have unsubscribed, it will unsubscribe from the source observable. Because the observable is multicasting, it makes the stream hot. This is an alias for multicast(() => new Subject()), refCount().

Syntax:

Following is the syntax of the RxJS share() multicasting operator:

Or

Parameter Explanation

There is no such parameter that we have to explain.

Return value

The RxJS share() operator returns observable causes the source observable to emit items to its observers when the connection is established.

Let us see some examples of the RxJS share() operator to understand it clearly.

Example 1

Output:

After executing the above example, you will see the following result:

RxJS share() Multicasting Operator

Example 2 (Multiple subscribers sharing source)

Output:

After executing the above example, you will see the following result:

RxJS share() Multicasting Operator


Next TopicRxJS Operators

You may also like