Why Are So Many Republicans Running for the Exits?

Congress just gaveled in for the second half of the 115th Congress and already a record number of senior Republican lawmakers, along with some vulnerable incumbents, are running for the exits. But in…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Basics of Reactive Programming

In this modern world, where everyone is using their time as a tool and not as a couch. How can an application rely on traditional blocking programming paradigms and not on reactive/non-blocking programming paradigms.

In this article, we are going to learn the basic concepts of the Reactive Programming. Why reactive programming is being used? What is the problem we are facing with the traditional programming paradigm?

The only answer to this question is that we want to improve the user experience. We want to make our application more responsive. We want to deliver a smooth user experience to our users by improving the response time and up time of our applications and perform all the complex and heavy calculations on our servers rather than on mobile devices. So all these problems are solved with a new way of writing code called reactive programming.

Reactive programming or Reactive Extensions(Rx) or Non-blocking programming architecture is a programming paradigm that focuses on asynchronous data streams and the propagation of changes to those streams. At the core of reactive programming is the concept of an observable sequence, which represents a stream of data that can be observed and reacted to. Observables can emit zero or more items over time, and observers can react to these items as they are emitted.

In other words, reactive programming means a paradigm in which data is asynchronously flowing in streams where a publisher emits the data and an observer is subscribing the data from streams. All these things keeps on happening asynchronously in an event loop which ends when publisher is left with no data or any occurs in between the process.

Events in reactive programming: In reactive programming, events are the changes or updates that occur over time and are processed by observables and subscribers. Some of the basic events are:

At any point of time, a stream can emit an item, an error event or a complete event but once an error or complete event is emitted, then after that the data stream can’t return anything. Thats why these events are called terminal events.

Let’s look at a practical example and summarise all we have understood above with some piece of code:

Don’t take care of this flux, we will discuss this later on in other article. Here Flux is acting as a subscriber which is basically generating a async stream of numbers one by one.

The events doOnNext() is like what to do if some data comes from stream.
doFinally() is acting as a complete event which means stream will not emit data after this event. doOnError() is what to do if an error comes and as its a terminal event because error is not handled stream stopped emitting data after it.

Output:

So by now you should be able to understand, why we need reactive programming, why we need them and how we can implement them. In the upcoming articles, we are going to learn how to use RxJava and it’s operators in detail.

Add a comment

Related posts:

How Can We Get Better At Being Mindful?

What does it mean to be mindful? If you have a wandering mind, live a fast-paced lifestyle, feel like you’re always rushing from one thing to the next, you could benefit from practicing mindfulness…

MY JOURNEY SO FAR IN GIRLSCODING.

My name is James Tomisin, i am 15 years old, i attend herbert macauly girls senior high school, i am currently in ss1 around 2017/2018 session. I am so glad! about writing my story in medium.com. My…

Are your ATM fees driving away cardholders?

Continuing growth in the use of smartphones, debit cards, and credit has turned “cashless” into a buzzword in Western culture. Enthusiasm for a currency-free future is further spurred by hype…