c# - combining one observable with latest from another observable -


i'm trying combine 2 observables values share key.

i want produce new value whenever first observable produces new value, combined latest value second observable selection depends on latest value first observable.

pseudo code example:

var obs1 = observable.interval(timespan.fromseconds(1)).select(x => tuple.create(somekeythatvaries, x)  var obs2 = observable.interval(timespan.frommilliseconds(1)).select(x => tuple.create(somekeythatvaries, x)  x in obs1   let latestfromobs2wherekeymatches = …   select tuple.create(x, latestfromobs2wherekeymatches) 

any suggestions?

clearly implemented subcribing second observable , creating dictionary latest values indexable key. i'm looking different approach..

usage scenario: 1 minute price bars computed stream of stock quotes. in case key ticker , dictionary contains latest ask , bid prices concrete tickers, used in computation.

(by way, thank dave , james has been fruitful discussion)

(sorry formatting, hard right on ipad..)

...why looking different approach? sounds on right lines me. it's short, simple code... speaking like:

var cache = new concurrentdictionary<long, long>();     obs2.subscribe(x => cache[x.item1] = x.item2);     var results = obs1.select(x => new {     obs1 = x.item2,     cache.containskey(x.item1) ? cache[x.item1] : 0 }); 

at end of day, c# oo language , heavy lifting of thread-safe mutable collections done you.

there may fancy rx approach (feels joins might involved)... how maintainable be? , how perform?

$0.02


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -