Rx.NET in Action
eBook - ePub

Rx.NET in Action

Tamir Dresher

Condividi libro
  1. 344 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Rx.NET in Action

Tamir Dresher

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Summary Rx.NET in Action teaches developers how to build event-driven applications using the Reactive Extensions (Rx) library.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology Modern applications must react to streams of data such as user and system events, internal messages, and sensor input. Reactive Extensions (Rx) is a.NET library containing more than 600 operators that you can compose together to build reactive client- and server-side applications to handle events asynchronously in a way that maximizes responsiveness, resiliency, and elasticity. About the Book Rx.NET in Action teaches developers how to build event-driven applications using the Rx library. Starting with an overview of the design and architecture of Rx-based reactive applications, you'll get hands-on with in-depth code examples to discover firsthand how to exploit the rich query capabilities that Rx provides and the Rx concurrency model that allows you to control both the asynchronicity of your code and the processing of event handlers. You'll also learn about consuming event streams, using schedulers to manage time, and working with Rx operators to filter, transform, and group events. What's Inside

  • Introduction to Rx in C#
  • Creating and consuming streams of data and events
  • Building complex queries on event streams
  • Error handling and testing Rx code


About the Reader Readers should understand OOP concepts and be comfortable coding in C#. About the Author Tamir Dresher is a senior software architect at CodeValue and a prominent member of Israel's Microsoft programming community. Table of Contents

PART 1 - GETTING STARTED WITH REACTIVE EXTENSIONS

  • Reactive programming
  • Hello, Rx
  • Functional thinking in C#

PART 2 - CORE IDEAS

  • Creating observable sequences
  • Creating observables from.NET asynchronous types
  • Controlling the observer-observable relationship
  • Controlling the observable temperature
  • Working with basic query operators
  • Partitioning and combining observables
  • Working with Rx concurrency and synchronization
  • Error handling and recovery

APPENDIXES

  • Writing asynchronous code in.NET
  • The Rx Disposables library
  • Testing Rx queries and operators

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Rx.NET in Action è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Rx.NET in Action di Tamir Dresher in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Software Development. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Editore
Manning
Anno
2017
ISBN
9781638357032

Part 1. Getting started with Reactive Extensions

What are reactive applications? What are they good for? How does programming with Reactive Extensions (Rx) change the way you write code? What should you do before you start working with Rx? And why is Rx better than traditional event-driven programming? These are the questions we’ll begin to address in these first three chapters.
You’ll learn what reactive systems and applications are, and why you should care. You’ll see a real example of creating an application that uses Rx and what you need to do to create your own Rx applications. You’ll also look at the functional programming foundations that Rx is based on, to make it easier to understand the rest of the concepts that this book introduces.

Chapter 1. Reactive programming

This chapter covers
  • Being reactive
  • Thinking about events as streams
  • Introducing Reactive Extensions (Rx)
The reactive programming paradigm has gained increasing popularity in recent years as a model that aims to simplify the implementation of event-driven applications and the execution of asynchronous code. Reactive programming concentrates on the propagation of changes and their effects—simply put, how to react to changes and create data flows that depend on them.[1]
1
This book is about reactive programming and not about functional reactive programming (FRP). FRP can operate on continuous time, whereas Rx can operate only on discrete points of time. More info can be found at the FRP creator’s keynote, http://mng.bz/TcB6.
With the rise of applications such as Facebook and Twitter, every change happening on one side of the ocean (for example, a status update) is immediately observed on the other side, and a chain of reactions occurs instantly inside the application. It shouldn’t come as a surprise that a simplified model to express this reaction chain is needed. Today, modern applications are highly driven by changes happening in the outside environment (such as in GPS location, battery and power management, and social networking messages) as well as by changes inside the application (such as web call responses, file reading and writing, and timers). To all of those events, the applications are reacting accordingly—for instance, by changing the displayed view or modifying stored data.
We see the necessity for a simplified model for reacting to events in many types of applications: robotics, mobile apps, health care, and more. Reacting to events in a classic imperative way leads to cumbersome, hard-to-understand, and error-prone code, because the poor programmer who is responsible for coordinating events and data changes has to work manually with isolated islands of code that can change that same data. These changes might happen in an unpredictable order or even at the same time. Reactive programming provides abstractions to events and to states that change over time so that we can free ourselves from managing the dependencies between those values when we create the chains of execution that run when those events occur.
Reactive Extensions (Rx) is a library that provides the reactive programming model for .NET applications. Rx makes event-handling code simpler and more expressive by using declarative operations (in LINQ style) to create queries over a single sequence of events. Rx also provides methods called combinators (combining operations) that enable you to join sequences of events in order to handle patterns of event occurrences or the correlations between them. At the time of this writing, more than 600 operations (with overloads) are in the Rx library. Each one encapsulates recurring event-processing code that otherwise you’d have to write yourself.
This book’s purpose is to teach you why you should embrace the reactive programming way of thinking and how to use Rx to build event-driven applications with ease and, most important, fun. The book will teach you step by step about the various layers that Rx is built upon, from the building blocks that allow you to create reactive data and event streams, through the rich query capabilities that Rx provides, and the Rx concurrency model that allows you to control the asynchronicity of your code and the processing of your reactive handlers. But first you need to understand what being reactive means, and the difference between traditional imperative programming and the reactive way of working with events.

1.1. Being reactive

As changes happen in an application, your code needs to react to them; that’s what being reactive means. Changes come in many forms. The simplest one is a change of a variable value that we’re so accustomed to in our day-to-day programming. The variable holds a value that can be changed at a particular time by a certain operation. For instance, in C# you can write something like this:
int a = 2; int b = 3; int c = a + b; Console.WriteLine("before: the value of c is {0}",c); a=7; b=2; Console.WriteLine("after: the value of c is {0}",c);
The output is
before: the value of c is 5 after: the value of c is 5
In this small program, both printouts show the same value for the c variable. In our imperative programming model, the value of c is 5, and it will stay 5 unless you override it explicitly.
Sometimes you want c to be updated the moment a or b changes. Reactive programming introduces a different type of variable that’s time varying: this variable isn’t fixed to its assigned value, but rather the value varies by reacting to changes that happen over time.
Look again at our little program; when it’s running in a reactive programming model, the output is
before: the value of c is 5 after: the value of c is 9
“Magically” the value of c has changed. This is due to the change that happened to its dependencies. This process works just like a machine that’s fed from two parallel conveyers and produces an item from the input on either side, as shown in figure 1.1.
Figure 1.1. A reactive representation of the function c = a + b. As the values of a and b are changing, c’s value is changing as well. When a is 7 and b is 2, c automatically changes to 9. When b changes to 1, c becomes 8 because a’s value is still 7.
You might find it surprising, but you’ve probably worked with reactive applications for years. This concept of reactiveness is what makes your favorite spreadsheet application so easy and fun to use. When you create this type of equation in a spreadsheet cell, each time you change the value in cells that feed into the equation, the result in the final cell changes automatically.

1.1.1. Reactiveness in your application

In a real-world application, you can spot possible time-variant variables in many circumstances—for instance, GPS location, temperature, mouse coordinates, or even text-box content. All of these hold a value ...

Indice dei contenuti