{"id":531,"date":"2009-11-27T20:45:16","date_gmt":"2009-11-27T19:45:16","guid":{"rendered":"http:\/\/www.minddriven.de\/?p=531"},"modified":"2009-11-28T15:34:51","modified_gmt":"2009-11-28T14:34:51","slug":"news-on-rx-reactive-extensions-for-net","status":"publish","type":"post","link":"https:\/\/www.minddriven.de\/index.php\/technology\/dot-net\/news-on-rx-reactive-extensions-for-net","title":{"rendered":"News on Rx (Reactive Extensions for .NET)"},"content":{"rendered":"<p><a href=\"http:\/\/www.minddriven.de\/wp-content\/uploads\/2009\/11\/Rx_Logo_512.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-543\" title=\"Rx Logo - Reactive Framework - Reactive Extensions for .NET\" src=\"http:\/\/www.minddriven.de\/wp-content\/uploads\/2009\/11\/Rx_Logo.png\" alt=\"Rx Logo - Reactive Framework - Reactive Extensions for .NET\" width=\"256\" height=\"256\" srcset=\"https:\/\/www.minddriven.de\/wp-content\/uploads\/2009\/11\/Rx_Logo.png 256w, https:\/\/www.minddriven.de\/wp-content\/uploads\/2009\/11\/Rx_Logo-150x150.png 150w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a>As <a href=\"http:\/\/www.minddriven.de\/?p=512\">written<\/a> before the Reactive Extensions for .NET (Rx, aka &#8222;Reactive Framework&#8220;) have been published as pre-release on their own <a href=\"http:\/\/msdn.microsoft.com\/en-us\/devlabs\/ee794896.aspx\">DevLabs<\/a>-site. The Rx-team is asking for feedback from you as developers and will include improvements into timely released development packages, until they&#8217;ll ship the final pieces with .NET 4.0. Check out the <a href=\"http:\/\/www.minddriven.de\/wp-content\/uploads\/2009\/11\/Rx_Logo_512.png\">MSDN forum<\/a> to give your feedback or ask for support.<\/p>\n<p>So what&#8217;s new in Rx compared to the early DLL from the Silverlight 3 toolkit sources?<\/p>\n<p>In general, many improvements were made on the API and <strong>functionality<\/strong>: methods on the <code>Observable<\/code> class have been rearranged and extended to give you full flexibility in many use cases. One method that I really love is <strong><code>Throttle()<\/code><\/strong>. Imagine that you have a textbox and everytime the user makes an input (without pressing Return) a data source is queried for items that match this input in some way (e.g. filtering by name or something). Now you discover that you&#8217;ve got performance issues. The search is done as the user types the first character and that&#8217;s not what you want. You only want to react to user&#8217;s input if he isn&#8217;t typing anything for -let&#8217;s say- 1 second. <code>Throttle()<\/code> solves this for you by one method call, you do not need anything else or do something manually. That&#8217;s great! Try to develop this with common event-based programming and you know what I mean&#8230;<\/p>\n<p>Then the Rx-team intends to <strong>converge <\/strong>the functionality of IEnumerable and IObservable. IObservable has much of the functionality of IEnumerable and LINQ operators make composing, filtering and transformation of event streams very simple and intuitive. And in the DevLabs-release of Rx the Rx-team is moving some functionality from IObservable (such as the <code>Amb()<\/code> method) to IEnumerable as well. If you need it or not: this is leveraging the dualism of both concepts for developers and makes both interfaces more intuitively usable.<\/p>\n<p>Furthermore the ground base of Rx is now Px (or PFx), the <strong>Parallel Extensions<\/strong> for .NET that will be part of .NET 4.0 as well. For every concurrent operation Px is taken and does the whole work (by creating a <code>Task&lt;T&gt;<\/code>). As a side effect of supporting Rx for .NET 3.5 SP1, the Rx-team has back-ported Px from .NET 4.0 to .NET 3.5 SP1 and made it usable for this platform as well. Great job!<\/p>\n<p>One thing very cool and worth to mention are <strong>Subjects <\/strong>as new components in Rx. Subjects implement the type <code>ISubject&lt;S,T&gt;<\/code> and are kind of hybrids between <code>IObserver&lt;S&gt;<\/code> and <code>IObservable&lt;T&gt;<\/code>. A Subject implements both <code>IObservable<\/code> and <code>IObserver<\/code> and can be seen as &#8222;channel&#8220; or &#8222;transforming storage&#8220;. The channel behavior is that you can push values as <em>input<\/em> into the subject via the <code>IObserver<\/code> methods (<code>OnNext()<\/code>, <code>OnCompleted()<\/code> and <code>OnError()<\/code>) and that you can subscribe to the Subject via the <code>IObservable.Subscribe()<\/code> method to get the <em>output<\/em> from the Subject. The Subject itself can do some <em>transformation<\/em> with the values that are pushed into it, can store the values and is able to take responsibility of what happens if someone subscribes to it. Subjects act as <em>storage<\/em> as well. When values are flowing into the Subject it can store them (or only the last or some transformed value, &#8230;) and when someone subscribes it can return all stored values (or only the last etc.). That means that e.g. an asynchronous operation needs not to be executed multiple times when using Subjects. The return value is stored in the Subject and can be extracted everytime a client subsribes to the Subject (independent of the moment of the subscription).<br \/>\nDependent on the intent of the Subject, Rx comes with several implementations that differ in their transformation and output behavior:<\/p>\n<ul>\n<li><strong><code>AsyncSubject&lt;T&gt;<\/code><\/strong>: This subject is used for asynchronous operations where only one value is expected as result. Thus the <code>AsyncSubject<\/code> remembers only the last value.<\/li>\n<li><strong><code>BehaviorSubject&lt;T&gt;<\/code><\/strong>: This subject always has a current value and fires everytime the value changes. Thus it&#8217;s kind of the <code>INotifyPropertyChanged<\/code> event.<\/li>\n<li><strong><code>EventSubject&lt;T&gt;<\/code><\/strong>: This subject corresponds to an event stream and thus will never invoke <code>OnError()<\/code> or <code>OnCompleted()<\/code>.<\/li>\n<li><strong><code>ReplaySubject&lt;T&gt;<\/code><\/strong>: This subject is like a tape\/video recorder. It records all events that are pushed into it and can be replayed. On replay it will return all events that have been recorded in exactly the same order and time interval in which they occurred.<\/li>\n<\/ul>\n<p>Another really nice development is an Add-In for Visual Studio: <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/en-us\/0791089a-4570-4f21-b5ee-78aba7e80651\"><strong>Reactive Extensions Generator<\/strong><\/a>. It overcomes the problem that all types in the .NET Framework rely on .NET events and don&#8217;t offer methods or properties that return corresponding instances of <code>IObservable<\/code>. This tool allows you to choose an assembly and it generates extension methods for all .NET events that it finds on the components of the assembly. Those methods will return the Observable pendants for those events instead. Really impressing stuff and very timely! Single drawback: it can be used only with\u00a0 Visual Studio 2010 and .NET 4.0.<\/p>\n<div>So to sum up again: I think Rx is valuable in many situations. First it&#8217;s a better <strong>pattern<\/strong> for reactive programming that unifies asynchronous programming (that normally returns just one value) and event-based programming (that typically has an infinite event-stream) and second it&#8217;s very strong when you want to <strong>compose <\/strong>(+ filter and transform) several event streams and when you want to build up and react to very special and complex events. Stay tuned for more information and examples on that in upcoming blog posts.<\/div>\n<p><a href=\"http:\/\/www.dotnetkicks.com\/kick\/?url=http%3a%2f%2fwww.minddriven.de%2f%3fp%3d531\"><img decoding=\"async\" src=\"http:\/\/www.dotnetkicks.com\/Services\/Images\/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.minddriven.de%2f%3fp%3d531\" border=\"0\" alt=\"kick it on DotNetKicks.com\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As written before the Reactive Extensions for .NET (Rx, aka &#8222;Reactive Framework&#8220;) have been published as pre-release on their own DevLabs-site. The Rx-team is asking for feedback from you as developers and will include improvements into timely released development packages, until they&#8217;ll ship the final pieces with .NET 4.0. Check out the MSDN forum to &hellip; <a href=\"https:\/\/www.minddriven.de\/index.php\/technology\/dot-net\/news-on-rx-reactive-extensions-for-net\" class=\"more-link\"><span class=\"screen-reader-text\">News on Rx (Reactive Extensions for .NET)<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[193,195,179,178,200],"class_list":["post-531","post","type-post","status-publish","format-standard","hentry","category-dot-net","tag-news","tag-reactive-extensions-for-net","tag-reactive-framework","tag-rx","tag-subjects"],"_links":{"self":[{"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/posts\/531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":9,"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/posts\/531\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.minddriven.de\/index.php\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}