Questions tagged [system.reactive]

System.Reactive refers to the Reactive Extensions for .NET, also known as Rx. Rx provides developers with a reactive programming model over the generic IObservable interface, as opposed to the traditional imperative programming model or the other reactive programming models that rely strictly on .NET Events or specific APIs.

A brief introduction

system.reactive refers to the Reactive Extensions (Rx), a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. System.Reactive is the root namespace used through the library. Using Rx, developers represent asychronous data streams using LINQ operators, and parameterize the concurrency in the asynchronous data streams using Schedulers. Simply put, Rx = Observables + LINQ + Schedulers.

Whether you are authoring a traditional desktop or web-based application, you have to deal with asynchronous and event-based programming from time to time. Desktop applications have I/O operations and computationally expensive tasks that might take a long time to complete and potentially block other active threads. Furthermore, handling exceptions, cancellation, and synchronization is difficult and error-prone.

Using Rx, you can represent multiple asynchronous data streams (that come from diverse sources, e.g., stock quote, tweets, computer events, web service requests, etc., and subscribe to the event stream using the IObserver<T> interface. The IObservable<T> interface notifies the subscribed IObserver<T> interface whenever an event occurs.

Because observable sequences are data streams, you can query them using standard LINQ query operators implemented by the Observable extension methods. Thus you can filter, project, aggregate, compose and perform time-based operations on multiple events easily by using these standard LINQ operators. In addition, there are a number of other reactive stream specific operators that allow powerful queries to be written. Cancellation, exceptions, and synchronization are also handled gracefully by using the extension methods provided by Rx.

Rx complements and interoperates smoothly with both synchronous data streams (IEnumerable<T>) and single-value asynchronous computations (Task<T>).

Source and further information

The project is actively developed by Microsoft Open Technologies, Inc., in collaboration with a community of open source developers. The source code is hosted on github here.

Additional documentation, video, tutorials and hands-on-labs are available on MSDN, and help and discussions the Rx Forums.

ReactiveX has been ported to many platforms, and information about supported platforms and links to platform specific implementations can be found here.

Related tags

3422 questions
16
votes
1 answer

Reactive Extensions: Concurrency within the subscriber

I'm trying to wrap my head around Reactive Extensions' support for concurrency and am having a hard time getting the results I'm after. So I may not get it just yet. I have a source that emits data into the stream faster than the subscriber can…
foomonkey42
  • 228
  • 2
  • 7
16
votes
6 answers

What is the purpose of returning an IDisposable in IObservable interface?

I'm going through the Head First Design Patterns book and doing my best to convert the code from their Java to C#. After the book discussed the observer pattern it mentioned that Java has classes/interfaces built in, as does .NET4. So I began…
15
votes
2 answers

How to convert a WPF Button.Click Event into Observable using Rx and F#

I am trying to replicate some C# code which creates an IObservable from a Button.Click event. I want to port this code to F#. Here is the original C# code which compiles without errors: Observable.FromEvent( …
Thorsten Lorenz
  • 11,781
  • 8
  • 52
  • 62
15
votes
2 answers

RX Scheduler - What is it?

I'm reading up on RX and totally bamboozled to what the Scheduler is intended for? Can someone explain?
Andy
  • 1,183
  • 5
  • 17
  • 25
15
votes
2 answers

Reactive Extensions for .NET (Rx): Take action once all events are completed

As a proof of concept, I want to write "Done" in a text box after a check box has been checked and a key has been pressed in a text box (in either order). I would expect this code to handle this, but it writes Done as soon as either event happens.…
Marcel Lamothe
  • 12,452
  • 9
  • 34
  • 44
15
votes
3 answers

RxJava - emit an observable every second

I am making a timer in Android using RxJava. I need to make a timer in RxJava to emit an observable every second. I have tried the following but with no luck. Any thoughts on what I am doing wrong? Observable.interval(1000L, TimeUnit.MILLISECONDS) …
fergdev
  • 963
  • 1
  • 13
  • 27
15
votes
3 answers

Executing TPL code in a reactive pipeline and controlling execution via test scheduler

I'm struggling to get my head around why the following test does not work: [Fact] public void repro() { var scheduler = new TestScheduler(); var count = 0; // this observable is a simplification of the system under test // I've just…
me--
  • 1,978
  • 1
  • 22
  • 42
15
votes
2 answers

Observable.Where with async predicate

Is there a convenient way to use an async function as the predicate of a Where operator on an observable? For example, if I have a nice tidy but possibly long-running function defined like this: Task Rank(object item); Is there a trick to…
MojoFilter
  • 12,256
  • 14
  • 53
  • 61
15
votes
2 answers

How to avoid the use of Subjects in RX

So I keep reading everywhere that use of Subject is "bad" - and I kind of agree with the reasoning. However, I am trying to think of the best way to avoid using it and have an example. Currently I have an abstract class for my persisted…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
15
votes
2 answers

How would you implement LINQ methods with SelectMany?

Erik Meijer is fond of pointing out that every LINQ function could actually be implemented by SelectMany; everything else is just a convenience. This is what Eric Lippert says answering a question about monads, but I've heard Erik Meijer say this…
lukebuehler
  • 4,061
  • 2
  • 24
  • 28
15
votes
3 answers

Combining boolean Observables

I have two streams signaling when some conditions change. I need an Observable which will fire true when all the conditions turn true. false when any of them turns false. If some of the conditions is false and another changes to false I don't need…
Pavel Murygin
  • 2,242
  • 2
  • 18
  • 26
15
votes
2 answers

Observable.Timer(): How to avoid timer drift?

In a C# (.NET 4.0) Application, I use the Reactive Extensions (2.0.20823.0) to generate time boundaries for grouping events into aggregate values. To simplify queries to the resulting database, these boundaries need to be aligned on full hours (or…
bastian schmick
  • 464
  • 3
  • 11
15
votes
2 answers

Observable.Defer - need some clarification as to what exactly it does

Say I want to generate an asynchronous stream of random numbers that pumps out a new value every 100 milliseconds. While trying to come up with a solution, my first attempt looked something like this: var random = new Random(); …
BFree
  • 102,548
  • 21
  • 159
  • 201
15
votes
4 answers

Is Reactive Extensions a good fit for a bus?

I have been using Rx for a little bit now to create an event bus (think CQRS/ES) within a single application, and it seems to work great. However, after surveying a bunch of different Event Sourcing frameworks, I have not seen Rx used once. It seems…
Erick T
  • 7,009
  • 9
  • 50
  • 85
15
votes
1 answer

IObservable<> missing .Subscribe extension methods

I'm using RX extensions and WF4 to create a workflow which reacts to observable messages to progress the workflow. To do this, I bring in an object containing an IObservable (ModuleMessage being my abstract class.) The problem I'm having is that…
Sprague
  • 1,610
  • 10
  • 22