Using Schedulers

A Scheduler is a mechanism to “schedule” an action to happen in the future. Each operator in RxJS uses one Scheduler internally, selected to provide the best performance in the most likely scenario.

Let’s see how we can change the Scheduler in operators and the consequences of doing so. First let’s create an array with 1,000 integers in it:

​ ​const​ itemArray = [];
​ ​for​ (​let​ i = 0; i < 1000; i++) {
​  itemArray.push(i);
​ }

Then, we create an Observable from arr and force it to emit all the notifications by subscribing to it. In the code we also measure the amount of time it takes to emit all the notifications:

​ ​const​ timeStart = Date.now();
​ Observable.​from​(itemArray).subscribe(​ ...

Get Reactive Programming with RxJS 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.