What is asynchronous and Is Reactive Programming must be asynchronous?

Viewed 470

In wiki:

In computing, reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change. With this paradigm, it's possible to express static (e.g., arrays) or dynamic (e.g., event emitters) data streams with ease, and also communicate that an inferred dependency within the associated execution model exists, which facilitates the automatic propagation of the changed data flow.

So, Reactive Programming is just a declarative programming paradigm concerned with data streams. But why reactive programming are asynchronous programming in many circumstances?

1 Answers

Asynchronous programming is the user of execution that occurs off of the main execution thread. This trends to consist of:

  1. defining some piece of work to do (eg: making a remote call)
  2. 'submiting' it to be executed if the main thread, which immediately returns an object such as a Promise, or a Future to the main thread. This object can be used to poll and retrieve the result of the asynchronous computation.
  3. Yielding a result from the previously returned object

This allows us to define execution logic as data and pass this around to be explicitly executed at the right time, or some variable number of times.

This works well with Reactive programming because this paradigm is declarative. The programmer declares the data structure and data transformations within their program, and the framework handles reacting to changes by applying the necessary transformations.

By writing data transformations as asynchronous code, the reactive framework can coordinate which transformations need to be performed and manage internally the invocation of your asynchronous functions and chaining of their results.

Related