Why does Publisher.multicast take a Subject?

From what I can gather so far, the result of multicast is much like the result of share, except the multicast publisher has a connect() method, so it let's you set up multiple subscribers before starting the flow of data.

But from that understanding, the signature might as well be multicast(), not multicast(subject: Subject).

What is the subject good for?
The multicast publisher uses value semantics, while the share publisher uses reference semantics, which allows more than subscriber to share the output of the publisher. Otherwise, all the publishers would need to execute for each subscriber, which might be wasteful, depending on the application.
Most operator return types are structs, while both share() and multicast() return a class type. If multicast returns a class, in what way is it using "value semantics"?
The first part of your question is about the difference between multicast() and share(). It's helpful to understand that share() is a more of a convenience, returning a Publishers.Share instance that does three things for you.
  • It uses a Publishers.Multicast to ensure multicasting behavior (it's legal for a publisher to be unicast, meaning that adding a second subscriber discards the subscription from the first).

  • Because Publishers.Mutlicast is a ConnectablePublisher, meaning you have to call connect() to start producing elements, the Publishers.Share instance uses a Publishers.Autoconnect, so that it starts producing values after the first subscriber attaches.

  • To produce the elements, the Publishers.Share instance uses a PassthroughSubject. This is more convenient than a CurrentSubject in that it doesn't need to be initialized with an initial value.

So, instead of thinking of them as peers, think of share() as building on multicast().

As for why the Publishers.Multicast needs a Subject and not some other kind of publisher, notice that the signature of the Subject protocol requires that its implementations conform to both Publisher and AnyObject. That means that Publishers.Multicast can assume reference semantics, and it can use Subject.send(_:) to send the values it receives to its various downstream subscribers.
It makes sense that that Publishers.Multicast uses the PassthroughSubject internally to implement its behavior, but that doesn't explain why the subject is exposed as an argument that you can pass in. Multicast could simply create it internally in its initializer. Taking it as an argument suggests there is some use case where you want to call send or otherwise do something with that subject, after you pass it in to multicast. I can't imagine such a use case. Can you think of an example?
Why does Publisher.multicast take a Subject?
 
 
Q