rxjs - 如何正确使用 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$);
,什么都不会发生。
我似乎无法伪造输入以使异步调度程序上的管道启动。我的测试只需要那个管子开火来看看有什么东西被调用了。
解决方案
发布后立即实现:
scheduled(events, asyncScheduler).subscribe(events$);
await lastValueFrom(events$)
推荐阅读
- mongodb - Mongoose - 无法插入字典类型的子文档
- java - Axon 框架:如何使用状态存储的聚合
- python - 将标签添加到任意密码查询中的所有节点
- html - 将 Aria 标签添加到视频元素
- android - 弹出软键盘时如何仅隐藏部分布局
- c# - .NetCore 中的 ArrayPool 是什么 - C#
- android - 应用级别的gradle文件中flutterversionNameflutterVersionCode的flutter问题
- c# - 使用辅助类中的 MVVM 模型从 WPF 应用程序获取 TextBox 名称
- jquery - Bootstrap v4 - btn-block 垂直间距?
- python - 如何过滤嵌套的 URL 列表?