Book Image

Reactive Programming for .NET Developers

Book Image

Reactive Programming for .NET Developers

Overview of this book

Reactive programming is an innovative programming paradigm focused on time-based problem solving. It makes your programs better-performing, easier to scale, and more reliable. Want to create fast-running applications to handle complex logics and huge datasets for financial and big-data challenges? Then you have picked up the right book! Starting with the principles of reactive programming and unveiling the power of the pull-programming world, this book is your one-stop solution to get a deep practical understanding of reactive programming techniques. You will gradually learn all about reactive extensions, programming, testing, and debugging observable sequence, and integrating events from CLR data-at-rest or events. Finally, you will dive into advanced techniques such as manipulating time in data-flow, customizing operators and providers, and exploring functional reactive programming. By the end of the book, you'll know how to apply reactive programming to solve complex problems and build efficient programs with reactive user interfaces.
Table of Contents (15 chapters)
Reactive Programming for .NET Developers
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface

Subscription life cycle


What will happen if we want to stop a single observer from receiving messages from the observable event source? If we change the program Main from the preceding example to the following one, we could experience a wrong observer life cycle design. Here's the code:

//this is the message observable responsible of producing messages 
using (var observer = new ConsoleIntegerProducer()) 
//those are the message observer that consume messages 
using (var consumer1 = observer.Subscribe(new IntegerConsumer(2))) 
using (var consumer2 = observer.Subscribe(new IntegerConsumer(3))) 
{ 
    using (var consumer3 = observer.Subscribe(new IntegerConsumer(5))) 
    { 
        //internal lifecycle 
    } 
 
    observer.Wait(); 
} 
 
Console.WriteLine("END"); 
Console.ReadLine(); 

Here is the result in the output console:

The third observer unable to catch value messages

By using the using construct method...