Multicast Operator

Rocket.multicastFunction
multicast(subject::S) where S
multicast(factory::F) where { F <: AbstractSubjectFactory }

The multicast()operator takes a Subject and uses it to share the source execution. It returns what’s known as aConnectableObservable`, which has a connect() method. It has one simple job - subscribes to the source with the provided subject.

Example

using Rocket

subject = make_subject(Int, mode = SYNCHRONOUS_SUBJECT_MODE)
source  = from(1:5) |> multicast(subject)

actor1 = logger("1")
actor2 = logger("2")

subscription1 = subscribe!(source, actor1)
subscription2 = subscribe!(source, actor2)

connect(source)

unsubscribe!(subscription1)
unsubscribe!(subscription2)
;

# output

[1] Data: 1
[2] Data: 1
[1] Data: 2
[2] Data: 2
[1] Data: 3
[2] Data: 3
[1] Data: 4
[2] Data: 4
[1] Data: 5
[2] Data: 5
[1] Completed
[2] Completed

See also: ConnectableObservable, make_subject, share, publish

source

See also

Operators