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

How to use Observable.FromEvent instead of FromEventPattern and avoid string literal event names

I'm learning my way around Rx within WinForms, and have the following code: // Create an observable from key presses, grouped by the key pressed var groupedKeyPresses = Observable.FromEventPattern(this, "KeyPress") …
ckittel
  • 6,478
  • 3
  • 41
  • 71
40
votes
5 answers

Rx - can/should I replace .NET events with Observables?

Given the benefits of composable events as offered by the Reactive Extensions (Rx) framework, I'm wondering whether my classes should stop pushing .NET events, and instead expose Rx observables. For instance, take the following class using standard…
Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
40
votes
5 answers

RxJava and parallel execution of observer code

I am having the following code using RxJava Observable api : Observable observable = fileProcessor.processFileObservable(processedFile.getAbsolutePath()); observable .buffer(10000) .observeOn(Schedulers.computation()) …
Pawan Mishra
  • 7,212
  • 5
  • 29
  • 39
40
votes
1 answer

IConnectableObservables in Rx

Can someone explain the differences between an Observable and a ConnectableObservable? The Rx Extensions documentation is very sparse and I don't understand in what cases the ConnectableObservable is useful. This class is used in the Replay/Prune…
Ray Booysen
  • 28,894
  • 13
  • 84
  • 111
39
votes
9 answers

Rx: How can I respond immediately, and throttle subsequent requests

I would like to set up an Rx subscription that can respond to an event right away, and then ignore subsequent events that happen within a specified "cooldown" period. The out of the box Throttle/Buffer methods respond only once the timeout has…
Andrew Anderson
  • 3,409
  • 22
  • 25
39
votes
2 answers

C# 5.0 async/await feature and Rx - Reactive Extensions

I am wondering what do the new C# 5.0 asynchronous features mean for Rx - Reactive Extensions? It seems to be not a replacement but they seem to overlap - Task and IObservable.
Mikhail Poda
  • 5,742
  • 3
  • 39
  • 52
39
votes
4 answers

EventBus/PubSub vs (reactive extensions) RX with respect to code clarity in a single threaded application

Currently, I am using an EventBus/PubSub architecture/pattern with Scala (and JavaFX) to implement a simple note organizing app (sort of like an Evernote client with some added mind mapping functionality) and I have to say that I really like…
39
votes
5 answers

Implementing IObservable from scratch

The Reactive Extensions come with a lot of helper methods for turning existing events and asynchronous operations into observables but how would you implement an IObservable from scratch? IEnumerable has the lovely yield keyword to make it very…
Jesper Larsen-Ledet
  • 6,625
  • 3
  • 30
  • 42
38
votes
8 answers

How to throttle event stream using RX?

I want to effectively throttle an event stream, so that my delegate is called when the first event is received but then not for 1 second if subsequent events are received. After expiry of that timeout (1 second), if a subsequent event was received I…
Alex
  • 551
  • 1
  • 5
  • 10
38
votes
6 answers

101 Rx Examples

EDIT: Thanks for the link to the wiki, I think that since its already started there, its easier to go there to check it out. However the question here is also good, so people who are not around the msdn forums get to know about the wiki and where it…
Francisco Noriega
  • 13,725
  • 11
  • 47
  • 72
35
votes
3 answers

Error Cannot convert lambda expression in subscribe for an IObservable

i am trying to implement a standard drag and drop image in wpf using Rx. var mouseDown = from evt in Observable.FromEventPattern(image, "MouseLeftButtonDown") select evt.EventArgs.GetPosition(image); …
ashutosh raina
  • 9,228
  • 12
  • 44
  • 80
35
votes
11 answers

Separate observable values by specific amount of time in RxJS

What would be the most idiomatic way to yield values of an Observable by a specific amount of time? For example, let's say I have an Observable created from a big Array and I want to yield a value every 2 seconds. Is a combination of interval and…
Sergi Mansilla
  • 12,495
  • 10
  • 39
  • 48
35
votes
9 answers

With Rx, how do I ignore all-except-the-latest value when my Subscribe method is running

Using Reactive Extensions, I want to ignore messages coming from my event stream that occur while my Subscribe method is running. I.e. it sometimes takes me longer to process a message than the time between message, so I want to drop the messages I…
Wilka
  • 28,701
  • 14
  • 75
  • 97
34
votes
4 answers

Reactive Observable Subscription Disposal

If I have access to an IObservable that I know is only ever going to return one item, will this work and is it the best usage pattern? IDisposable disposable = null; disposable = myObservable.Subscribe(x => { DoThingWithItem(x); if…
Noob
  • 1,049
  • 1
  • 10
  • 20
34
votes
4 answers

What is difference between push based and pull based structures like IEnumerable and IObservable

In every tech talk, or in every blog post I've read about IEnumerable and IObservable I read that, IEnumerable is pull-based structure and IObservable is push-based structure. I've read that with IObservable we have async calls, where nothing is…
Tornike Gomareli
  • 1,564
  • 2
  • 16
  • 28