Multicasting Operators
Share
ShareReplay
Publish Operator
PublishReplay Operator
PublishLast Operator
Share Operator
Here
Share source among multiple subscribers
Here we unsubscribe and notice stream is well unsubscribe after all Observer subscription are removed
Thanks to the call of the Do Debug Operator wich introduce a side-effect just to displauy the trace
Publish Operator
Here
Publish return an ConnectableObservable
interface ConnectableObservable< T > extends Observable< T > {
connect() : Subscription
refCount(): Observable< T >
}
Like a share Operator not garbage collected & emits data after a call to connect()
-The connect() method returns a Subscription instance that represents the shared underlying subscription. Unsubscribing from
it will result in both subscribers no longer receiving any events.
Here
-The refCount() method is named after the garbage collection concept known as ref counting, or reference counting.
The point is that it returns an observable sequence that stays connected to the source as long as there’s a least
one active subscription. Does this sound familiar? It should because the share() operator we discussed a moment ago
is little more than an alias for publish().refCount()
A connectable observable encapsulates the multicasting infrastructure, but does not immediately subscribe to the source.
It subscribes to the source when its connect method is called
refCount returns an observable that maintains a reference count of the subscriptions that have been made
publish.refCount !== share cause the latter return a new Subject unlike the first one
basically share becomes retriable unlike publish.refCount thus when refCount reach 0 and then a new Subscription coming share will could retry wheras publish.refCount throw the complete of is current complete Subject
PublishReplay Operator
This operator uses several parameters to determine the characteristics of a buffer to maintain
Here
Like a publish Operator but emitted previous values from a certain Buffer side parameter for each Observer Subscription
ShareReplay Operator
Here
Like a share Operator but emitted previous values from a certain Buffer side parameter for each Observer Subscription
PublishLast Operator
Here
Like a Last Operator with Hot Observable Behaviour
Other Multicasting Operators
multicasting => Share source utilizing the provided Subject
here
cache
publishBehaviour
multicast => Returns an Observable that emits the results of invoking a specified selector on items emitted by a ConnectableObservable that shares a single subscription to the underlying stream
here