java - PublishSubject to fire onNext when subscribed -
i'm trying create proxy models using rxjava, proxy lets other subscribe changes in model.
here's simplified version of proxy:
class mymodelproxy { private static mymodelproxy instance; private mymodel model; private publishsubject<mymodel> subject; private mymodelproxy() { this.model = // load cache this.subject = publishsubject.create(); } public static observable<mymodel> observe() { if (instance == null) { instance = new mymodelproxy(); } return instance.subject; } private void modelupdated() { this.subject.onnext(this.model); } } there's 1 instance of mymodel in system, might change on time, , want able register these updates.
code works if register on observable returned observe method before calling onnext of subject.
the behavior want when subscribe method called on observer current instance of mymodel sent subscriber subscribed.
i thought extending publishsubject it's final, thought writing own version of (mostly copying what's in publishsubject , adding need) found out subjectsubscriptionmanager has package visibility that's dead end too.
any ideas how can add needed functionality?
thanks.
there behaviorsubject, want: emits recent , future items subscribers
Comments
Post a Comment