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
18
votes
6 answers

Throttle Rx.Observable without skipping values

Throttle method skips values from an observable sequence if others follow too quickly. But I need a method to just delay them. That is, I need to set a minimum delay between items, without skipping any. Practical example: there's a web service which…
Athari
  • 33,702
  • 16
  • 105
  • 146
17
votes
2 answers

How do I throttle a slider's value change event?

I got a slider that on value change forces a fairly serious computation, so I want to throttle it to fire actual event after for example 50ms pass when user has finished sliding it. While I learned some various stuff about Rx its unclear how should…
Valentin Kuzub
  • 11,703
  • 7
  • 56
  • 93
17
votes
1 answer

Subscribing to observable sequence with async function

I have an asnyc function that I want to invoke on every observation in an IObservable sequence, limiting delivery to one event at a time. The consumer expects no more than one message in flight; and this is also the RX contract, if I understand it…
17
votes
6 answers

How to merge two sorted Observables into a single sorted Observable?

Given: Integer[] arr1 = {1, 5, 9, 17}; Integer[] arr2 = {1, 2, 3, 6, 7, 12, 15}; Observable o1 = Observable.from(arr1); Observable o2 = Observable.from(arr2); How to get an Observable that contains 1, 1, 2, 3, 5, 6, 7, 9, 12, 15,…
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
17
votes
5 answers

What is a good way to create an IObservable for a method?

Let's say, we have a class: public class Foo { public string Do(int param) { } } I'd like to create an observable of values that are being produced by Do method. One way to do it would be to create an event which is being called from Do…
Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99
17
votes
7 answers

How can I unit test code that contain Task.Delay?

How can I unit test component that has an await Task.Delay without really having to wait for it. For example, public void Retry() { // doSomething(); if(fail) await Task.Delay(5000); } I need to test the failure branch but I do not…
17
votes
4 answers

When to use IEnumerable vs IObservable?

How do you establish whether or not a method should return IEnumerable or IObservable? Why would I choose one paradigm over the other?
jmcg
  • 357
  • 3
  • 12
16
votes
1 answer

What are the use cases for TPL Dataflow over Reactive Extensions (Rx)

I'm specifically looking at writing some signal processing algorithms in one or other, or maybe some combination of both of these. Performance isn't a big concern, clarity of expressing intent is more important. I'd be looking to implement the…
16
votes
1 answer

How Async streams compares to reactive extension?

How to compare the following two? Is Rx more powerful? Reactive extension: var observable = Observable.Create(async (observer, cancel) => { while (true) { string line = await sr.ReadLineAsync(); if (line == null) …
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
16
votes
4 answers

Keeping references to `IDisposable` when using the Reactive Extensions for .NET: always, never, or sometimes?

Up until now I have zealously kept every reference to the IDisposable returned from any .Subscribe(...), .Connect(...), etc, method within Rx. I've done this because of my fear that a garbage collections will dispose the disposable if I don't keep…
Enigmativity
  • 113,464
  • 11
  • 89
  • 172
16
votes
2 answers

RxJava: How to conditionally apply Operators to an Observable without breaking the chain

I have a chain of operators on an RxJava observable. I'd like to be able to apply one of two operators depending on a boolean value without "breaking the chain". I'm relatively new to Rx(Java) and I feel like there's probably a more idiomatic and…
user1405990
  • 806
  • 1
  • 8
  • 19
16
votes
5 answers

Get previous element in IObservable without re-evaluating the sequence

In an IObservable sequence (in Reactive Extensions for .NET), I'd like to get the value of the previous and current elements so that I can compare them. I found an example online similar to below which accomplishes the…
dcstraw
  • 3,243
  • 3
  • 29
  • 38
16
votes
3 answers

Terminology: What is a "glitch" in Functional Reactive Programming / RX?

What is the definition of a "glitch" in the context of Functional Reactive Programming? I know that in some FRP frameworks "glitches" can occur while in others not. For example RX is not glitch free while ReactFX is glitch free [1]. Could someone…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
16
votes
2 answers

Reactive Extensions Subscribe calling await

I want to perform an async call based for each event raised by a Reactive Extensions Observable. I'm also trying to keep everything synchronized as I want the async call to finish before the next event is handled. How would one go about doing…
Daniel Little
  • 16,975
  • 12
  • 69
  • 93
16
votes
3 answers

RX: Run Zipped Observables in parallel?

So I'm playing around with RX (really cool), and I've been converting my api that accesses a sqlite database in Android to return observables. So naturally one of the problems I started to try to solve is, "What if I want to make 3 API calls, get…
spierce7
  • 14,797
  • 13
  • 65
  • 106