Rx\Observable::multicast PHP Method

multicast() public method

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, PublishLast, and Replay.
public multicast ( Rx\Subject\Subject $subject, null $selector = null, rx\SchedulerInterface $scheduler = null ) : Rx\Observable\ConnectableObservable | Rx\Observable\MulticastObservable
$subject Rx\Subject\Subject
$selector null
$scheduler rx\SchedulerInterface
return Rx\Observable\ConnectableObservable | Rx\Observable\MulticastObservable
    public function multicast(Subject $subject, $selector = null, SchedulerInterface $scheduler = null)
    {
        return $selector ? new MulticastObservable($this, function () use($subject) {
            return $subject;
        }, $selector) : new ConnectableObservable($this, $subject, $scheduler);
    }

Usage Example

Example #1
0
 /**
  * @param \Rx\ObserverInterface $observer
  * @param null $scheduler
  * @return \Rx\Disposable\BinaryDisposable
  */
 public function subscribe(ObserverInterface $observer, $scheduler = null)
 {
     $connectable = $this->source->multicast(call_user_func($this->fn1));
     $observable = call_user_func($this->fn2, $connectable);
     return new BinaryDisposable($observable->subscribe($observer, $scheduler), $connectable->connect());
 }