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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -