Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Best way to create a multicast-able createObservableFunction observable? #51

Open
thomaslundstrom opened this issue Dec 4, 2014 · 2 comments

Comments

@thomaslundstrom
Copy link

I recently had the same problem as http://stackoverflow.com/questions/26664793/createobservablefunction-subscriber-gets-overriden
where trying to subscribe() multiple times to the same observable created via $scope.$createObservableFunction overwrites the previous subscription (see the StackOverflow code example).

In a comment to the question, the person asking the question followed up with

"In order to multicast it you need to do $createObservableFunction().publish().refCount() to keep the > the connection to the source."

I can confirm this works with multiple subscriptions. Is there another (better) way of doing this?

@PhiLhoSoft
Copy link

I am only a beginner at RxJS, but from what I saw so far, using .publish().refCount() (or .share(), as said in the answer, which is the same thing) is the blessed way to do this.
You will see this couple used a lot in the source code of this library.

@PhiLhoSoft
Copy link

Mmm, I haven't seen the question is nearly one year old...
Looking at the source, I see:

Rx.createObservableFunction = function (self, functionName, listener) {
  return new CreateObservableFunction(self, functionName, listener).publish().refCount();
};

so I guess the issue is already addressed and should be closed...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants