c# - Rx how to create a sequence from a pub/sub pattern -


i'm trying evaluate using rx create sequence pub/sub pattern (i.e. classic observer pattern next element published producer(s)). same .net events, except need generalize such having event not requirement, i'm not able take advantage of observable.fromevent. i've played around observable.create , observable.generate , find myself end having write code take care of pub/sub (i.e. have write producer/consumer code stash published item, consume calling iobserver.onnext() it), seems i'm not taking advantage of rx...

am looking down correct path or fit rx?

thanks

your publisher exposes iobservables properties. , consumers subscribe them (or rx-fu want before subscribing).

sometimes simple using subjects in publisher. , more complex because publisher observing other observable process.

here dumb example:

public class publisher {     private readonly subject<foo> _topic1;      /// <summary>observe foo values on topic</summary>     public iobservable<foo> footopic     {        { return _topic1.asobservable(); }     }      private readonly iobservable<long> _topic2;      /// <summary>observe current time whenever our clock ticks</summary>     public iobservable<datetime> clockticktopic     {         { return _topic2.select(t => datetime.now); }     }      public publisher()     {          _topic1 = new subject<foo>();          // tick once each second          _topic2 = observable.interval(timespan.fromseconds(1));     }      /// <summary>let know new foo</summary>     public newfoo(foo foo) { _topic1.onnext(foo); } }   // interested code... publisher p = ...; p.footopic.subscribe(foo => ...);  p.clickticktopic.subscribe(currenttime => ...);  // count how many foos occur during each clock tick p.footopic.buffer(p.clockticktopic)     .subscribe(foos => console.writeline("{0} foos during interval", foos.count)); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -