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
22
votes
2 answers

Using Reactive Extensions (Rx) for socket programming practical?

What is the most succint way of writing the GetMessages function with Rx: static void Main() { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var messages = GetMessages(socket,…
Joseph Kingry
  • 8,188
  • 4
  • 36
  • 52
22
votes
2 answers

How can I see what my reactive extensions query is doing?

I'm writing a complex Reactive Extensions query with lots of operators. How can I see what's going on? I'm asking and answering this as it comes up a fair bit and is probably of good general use.
James World
  • 29,019
  • 9
  • 86
  • 120
22
votes
3 answers

I/O performance - async vs TPL vs Dataflow vs RX

I have a piece of C# 5.0 code that generates a ton of network and disk I/O. I need to run multiple copies of this code in parallel. Which of the following technologies is likely to give me the best performance: async methods with await directly use…
22
votes
3 answers

Reactive Extensions OnNext thread-safety

With the Rx Subject, is it thread-safe to call OnNext() from multiple threads? So the sequence can be generated from multiple sources. Will merge do the same thing?
21
votes
4 answers

Immediate debounce in Rx

I am looking an operator to debounce a series of event, let us say user's click. The input and output should be like this: interval : -> <- -> <- in : 1--2--3-------4--5--5--6-7-8-------- out :…
Quang Linh Le
  • 751
  • 1
  • 7
  • 16
21
votes
1 answer

What are the differences between TPL Dataflow(TDF) and Reactive Extensions?

After days of googleing I think I can't decide which one is for what scenario. Of course I would like to use a perfect framework which combines both (unrealistic of course). I even know that it's possible to use them together. But the real question…
naeron84
  • 2,955
  • 3
  • 30
  • 37
20
votes
1 answer

Advanceable historical stream and live stream in Rx

I have a hot observable that I normally implement using a normal Subject underneath, so that those interested could subscribe to a live a stream of notifications. Now I would like to keep that live stream, but also expose a historical stream of all…
Cel
  • 6,467
  • 8
  • 75
  • 110
20
votes
2 answers

IObserver and IObservable in C# for Observer vs Delegates, Events

All I am trying to do is implementing the observer pattern. So, I came up with this solution: We have a PoliceHeadQuarters whose primary job is to send notifications to all those who are subscribed to it. Consider that the DSP, Inspector and…
20
votes
3 answers

A code example illustrating the difference between the paradigms of async/await and Reactive (Rx) extension?

Both the System.Reactive extension for .NET and new C# 5.0 (.NET 4.5) async/await pursue (or based on) future and promises constructs paradigm (approach). Can you give the (*) simplest C# code example illustrating the difference between them? …
20
votes
4 answers

Should I expose IObservable on my interfaces?

My colleague and I have dispute. We are writing a .NET application that processes massive amounts of data. It receives data elements, groups subsets of them them into blocks according to some criterion and processes those blocks. Let's say we have…
Alex Shtoff
  • 2,520
  • 1
  • 25
  • 53
19
votes
1 answer

Rx IObservable buffering to smooth out bursts of events

I have an Observable sequence that produces events in rapid bursts (ie: five events one right after another, then a long delay, then another quick burst of events, etc.). I want to smooth out these bursts by inserting a short delay between events. …
Dan Kroymann
  • 282
  • 2
  • 9
19
votes
1 answer

Do we need to unsubscribe from observable that completes/errors-out?

When I know that the observable will definitely complete (either with complete or an error notification) before my component/class goes out of scope, do I still need to unsubscribe from it to prevent memory leaks? In other words, is…
Titan
  • 2,875
  • 5
  • 23
  • 34
19
votes
4 answers

How to Subscribe with async method in Rx?

I have following code: IObservable _source; ... _source.Subscribe(StoreToDatabase); private async Task StoreToDatabase(Data data) { await dbstuff(data); } However, this does not compile. Is there any way how to observe data…
nothrow
  • 15,882
  • 9
  • 57
  • 104
19
votes
3 answers

Angular2 Observable.forkJoin of observable variables - ReferenceError: Observable is not defined

I'd like to ask you for help. I omitted code that I assume is not important. Let's imagine TS file that contains service calls: // file: someService.ts @Injectable() export class SomeService { method1(){ var observable =…
Tomino
  • 5,969
  • 6
  • 38
  • 50
19
votes
4 answers

Reactive Extensions vs FileSystemWatcher

One of the things that has long bugged me about the FileSystemWatcher is the way it fires multiple events for a single logical change to a file. I know why it happens, but I don't want to have to care - I just want to reparse the file once, not 4-6…
Joel Mueller
  • 28,324
  • 9
  • 63
  • 88