RxJS:使用调度程序

目录

调度程序控制何时必须启动和通知订阅的执行。

要使用调度程序,我们需要以下内容:

import { Observable, asyncScheduler } from 'rxjs';
import { observeOn } from 'rxjs/operators';

这是一个工作示例,其中,我们将使用调度程序来决定执行情况。

import { Observable, asyncScheduler } from 'rxjs';
import { observeOn } from 'rxjs/operators';

var observable = new Observable(function subscribe(subscriber) {
   subscriber.next("My First Observable");
   subscriber.next("Testing Observable");
   subscriber.complete();
}).pipe(
   observeOn(asyncScheduler)
);
console.log("Observable Created");
observable.subscribe(
   x => console.log(x),
   (e)=>console.log(e),
   ()=>console.log("Observable is complete")
);

console.log('Observable Subscribed');

输出

RxJS:使用调度程序

没有调度程序,输出将如下所示:

RxJS:使用调度程序

作者:terry,如若转载,请注明出处:https://www.web176.com/rxjs/1755.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2021年2月7日 下午9:50
下一篇 2021年2月8日 上午11:33

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注