Search⌘ K

Synchronous Vs. Asynchronous Data Sources

Understand the distinction between synchronous and asynchronous data sources in RxJS. Explore how observables emit data from arrays, promises, and DOM events, and learn how to convert static data sources into asynchronous streams. This lesson prepares you to handle data streams effectively in reactive programming.

One common misunderstanding, especially when testing reactive streams, is treating synchronous data sources as asynchronous. So, understanding the difference between these types of data sources is quite essential before moving forward.

Synchronous data sources

Every reactive library offers the possibility of creating a stream from different types of data. For this example, we are going to take into consideration a simple array [2, 12, 35] that will be wrapped into an observable:

Javascript (babel-node)
const {from} = require("rxjs")
const sourceA = from([2, 12, 35]);
sourceA.subscribe(console.log);

This example indicates that when the observable is subscribed to, the values of the array ...