Announcement

👇Official Account👇

图片

Welcome to join the group & private message

Article first/tail QR code

Skip to content

调度器 Schedulers

调度器控制何时何地执行订阅和发送通知。

调度器类型

  • queueScheduler: 在当前事件循环中同步执行
  • asyncScheduler: 使用 setTimeout 异步执行
  • asapScheduler: 使用 Promise.then 微任务执行
  • animationFrameScheduler: 在下一个 animation frame 执行

使用示例

typescript
import { of, queueScheduler } from 'rxjs';

queueScheduler.schedule(() => {
  of(1, 2, 3).subscribe(x => console.log(x));
});

通常不需要手动指定调度器,但在处理并发问题时调度器非常有用。

上次更新于: