RxJS - 实用操作符 observeOn

此操作符基于输入的调度程序,将从源可观察对象重新发出通知。

语法

observeOn(scheduler): Observable

参数

scheduler − 调度程序用作输入,有助于从源可观察对象重新发出通知。

返回值

它将返回与源可观察对象相同的可观察对象,但带有调度程序参数。

示例

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';
});

输出

observeOn Operator