Reputation: 6426
I try to use rx and PublishSubject
. So I create object:
PublishSubject<MyEvent> events = PublishSubject.create();
and in my service I put MyEvent
in that.
events.onNext(new MyEvent);
So sometimes I don't receive the first event, but the second I receive. And sometimes I receive all events. Can anybody explain, what problem can be here?
Upvotes: 1
Views: 2339
Reputation: 25573
PublishSubject
emits the event to all "currently subscribed" subscribers. It does not emit to subscribers that subscribe in the future.
BehaviorSubject
will emit the last known value when subscribed to, then behave like a PublishSubject
. My guess is that this is the behavior you expect.
Upvotes: 6