Rx.NET in Action
eBook - ePub

Rx.NET in Action

Tamir Dresher

Compartir libro
  1. 344 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Rx.NET in Action

Tamir Dresher

Detalles del libro
Vista previa del libro
Índice
Citas

Información del 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

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Rx.NET in Action un PDF/ePUB en línea?
Sí, puedes acceder a Rx.NET in Action de Tamir Dresher en formato PDF o ePUB, así como a otros libros populares de Computer Science y Software Development. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Editorial
Manning
Año
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 ...

Índice