首页 > 解决方案 > 如何正确使用 asyncScheduler 来了解 rxjs 中处理的数据?

问题描述

我有一些这样的基本代码:

this.events$
      .pipe(
        observeOn(asyncScheduler),
        ...
      ).subscribe(anotherObservable$);

这在我的应用程序中运行良好,但我在单元测试中遇到了一个有趣的问题。我放了几个这样的调试控制台:

    this.events$
      .pipe()
      .subscribe(console.log.bind(null, 'sanity check inside without async'));
    this.events$
      .pipe(observeOn(asyncScheduler))
      .subscribe(console.log.bind(null, 'sanity check inside with async'));

如果我from(events).subscribe(events$);在测试中这样做,则会触发“没有异步”日志。

如果我这样做scheduled(events, asyncScheduler).subscribe(events$);,什么都不会发生。

我似乎无法伪造输入以使异步调度程序上的管道启动。我的测试只需要那个管子开火来看看有什么东西被调用了。

标签: rxjs

解决方案


发布后立即实现:

scheduled(events, asyncScheduler).subscribe(events$);
await lastValueFrom(events$)

推荐阅读