I'm mostly a newbie to JavaScript and RxJs so my question may not even make sense but I'm trying to understand if Observables in RxJavaScript ought to be used in conjunction with an async library or does it handle it internally?
Asked
Active
Viewed 30 times
1 Answers
1
No it does not imply asynchronous and you do not need to use another async library. RxJS is about abstracting away the need to worry about how something gets executed and focusing on what gets executed. For instance if we had a function that simply multiplied values:
function square(x) { return x * x; }
The above does not know anything about asynchronous events so we can use it for either:
var counter = 1;
var immediate = Rx.Observable.from([1, 2, 3, 4, 5]);
var asynchronous = Rx.Observable.fromEvent(window, 'click', () => counter++);
immediate.map(square).subscribe(x => console.log('Sync: ' + x));
asynchronous.map(square).subscribe(x => console.log('Async: ' + x));
The first stream (by default) will execute synchronously and immediately, while the second executes asynchronously when the window is clicked on. Both use the same square
function without caring about whether the value is coming in synchronously or asynchronously.

paulpdaniels
- 18,395
- 2
- 51
- 55