RxJS - Utility Operator observeOn



This operator based on the input scheduler will reemit the notifications from the source Observable.

Syntax

observeOn(scheduler): Observable

Parameters

scheduler − The scheduler is used as an input that will help to re-emit the notifications from the source observable.

Return value

It will return an observable same as source observable, but with scheduler param.

Example

import { interval } from 'rxjs';
import { observeOn } from 'rxjs/operators';
import { animationFrameScheduler } from 'rxjs';

let testDiv = document.getElementById("test");
const intervals = interval(100);
let case1 = intervals.pipe(
   observeOn(animationFrameScheduler),
);
let sub1 = case1.subscribe(val => {
   console.log(val);
   testDiv.style.height = val + 'px';
   testDiv.style.width = val + 'px';
});

Output

observeOn Operator
Advertisements