RxJS - Utility Operator subscribeOn



This operator helps to asynchronous subscribes to the source Observable based on the scheduler taken as input.

Syntax

subscribeOn(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 { of, merge, asyncScheduler } from 'rxjs';
import { subscribeOn } from 'rxjs/operators';

let test1 = of(2, 4, 6, 8).pipe(subscribeOn(asyncScheduler));
let test2 = of(3, 6, 9, 12, 15);
let sub1 = merge(test1, test2).subscribe(console.log);

Output

subscribeOn Operator
Advertisements