- Events can be treated like Collection. Both are stream of items of a particular type
- Every Collection needs to implement IEnumerable
- Rx is a layer on top of disparate event (generated by disparate sources like cloud, svc, hardware) that can be consolidated into single collection
- So basically our code is Observer subscribing to a Rx Observable (collection of events)
- Now whenever a new event occurs in the world, Obbserver’s callback is called..so this is non blocking async action…
- IObservable can raise Next () when next event occurs, or Error() or complete() like Pub Sub Model
- Rx vs Events:
- Events aren’t 1st class, so can’t pass them around, while IObservable<T> is Type
- have to be managed individually, while Observable has dispose to dispose off all event handlers
- Observable implements iEnumerable and so can be enumerated or written LYNQ query on..
- BASICALLY RX OBSERVABLE<T> IS COLLECTION OF EVENTS, AND AN ABSTRACTION LAYER OVER EVENTS TO MANAGE THEM TOGETHER
- rx can be used from rx-main nuget .it has 4 dlls
- tO CREATE OBSERVABLE FROM NORMAL C# EVENTS: var observable = Observable.FromEventPattern(EVENT);
- then say observable.subscribe()
- But to do lynq, say: var observable = from _ in Observable.FromEventPattern(textbox) select textbox.text. Throttle()…ie you can use RX features on this iObservable stream..
- Now if another action needs to be performed on this stream, keep it ready:
- var result = from observalbe select …..
- Then subs to : result.subscribe(observable)