c# - Rx with external states -


rx external states?

so in example there rx functionality combined external state full behavior. best approach rx achieve this?

problematic code places 'updateactive'.

public enum source {     observable1,     observable2, }  // type source.observable1 iobservable<source> observable1;  // type source.observable2 iobservable<source> observable2;  var mergedobservables = observable1.select(x => source.observable1)     .merge(observable2.select(x => source.observable2));  var updateactive = false;  mergedobservables.subscribe(x => {     switch (x.source)     {         case source.observable1:         {             if (updateactive)                 break;              updateactive = true;              // here code causes observable2 new values.              // (this coud on other thread)             // if case, new value(s) should ignored.              updateactive = false;         }         break;          case source.observable2:         {             if (updateactive)                 break;              updateactive = true;              // here code causes observable1 new values.              // (this coud on other thread)             // if case, new value(s) should ignored.              updateactive = false;         }         break;     } }); 

remarks: how can transport 'updateactive' state within rx operators

you use instance of subject<bool> state carrier.

given:

subject<bool> isupdating = new subject<bool>(); 

you use in this:

var flaggedobservables = mergedobservables     .combinelatest(isupdating, (obs, flag) => new {obs, isupdating = flag});  flaggedobservables     .where(data => !data.isupdating)     .select(data => data.obs)     .distinctuntilchanged()     .subscribe(         obs =>         {             isupdating.onnext(true);              //do work on obs              isupdating.onnext(false);         }); 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -