Reactive Extensions (Rx) and .NET
Reactive Extensions (Rx) and .NET
The other day I came across a namespace I had not delved into - that of System.Reactive. ReactiveX or Rx is an older Microsoft technology that a ton of Javascript frameworks spun out from. It is kinda weird that the origin technology was Microsoft and no one really did anything with it or promoted it.
Rx is perfect for the distributed cloud-based applications and web of course. Rx is focused around the push data propagation rather than the pull.
Focus
Pull Push
Focus client requests, usually has response server pushes data to clients
Focus2 get when convenient for client send when convenient for server
Client/Server control client is in control server is in control
UI focus user entry (active) passive screen
Side Effects user convenience/user happy scalable
Examples
Pull Push
UI example button clicks & keyboard entry GPS & current state dashboard of servers
UI example2 sensor firing event stock market ticker & weather alerts
Email example "Send/Receive" button got new email when someone sent
Web examples button clicks on web page web site available for browser downloads
Web2 buying something on Ebay notifications
Computer Process data entry batch entry or time sharing
Hardware cheap PCs mainframes or web server
Communication polling notifications
Inventory example get when user asks - so delay; JIT; already on hand; inventory
Inventory example2 must order from supplier make and send out excess ahead of time
Code Impacts
Pull Push
Code "+=" event handlers Task<T>
Collections Enumerable collections Observable collections
Collection iteration Linq arose to address this Linq + extra commands required
Patterns Event & APIs & Request/Response Pub/Sub & Observer/Observable
Message Pattern? yes yes
The newer Rx PFX to handle concurrency such as handler locking. Error handling is tougher in Rx.
Rx gives interfaces for the custom Observer and Observable classes to respond to. Observable contract has an OnNext, OnError, OnCompletion, and OnSubscription methods. The Observer can Subscribe, Unsubscribe, and Request from the Observable. Rx returns back an IDisposable that the Observer should dispose in its Dispose() method.
Push/Pull
Rx could be combined with some other technology to do a "joint" push/pull propagation.
Examples
1) a) Push - start with light-weight notification from server
b) Pull - if interested, then pull the large payload down
Perhaps with software updates.
2) a) Pull - when initializing the display
b) Push - update thereafter when state actually changes
Perhaps with GPS so can see where things are initially
Comments
Post a Comment