rxjs - rxjs 定期或定时器到期时调用函数
问题描述
我需要在函数完成后每 5000 毫秒调用一次函数。我怎么能做到这一点。
即使函数需要更长的时间,我当前的实现也会每 5000 毫秒调用一次
const { BehaviorSubject, timer} = require("rxjs");
const subject = new BehaviorSubject(false)
async function doit() {
console.log('hey')
subject.next(true)
}
timer(0, 5000).subscribe(() => {
doit()
})
解决方案
使用exhaustMap,在doit完成之前不会占用新项目。确保它返回可观察的
timer(0, 5000).pipe(
exhaustMap(_ => doit())
).subscribe();
推荐阅读
- java - 使用 Selenium 网格和 jenkins 通过 Web 界面上传带有空手道测试的文件
- c++ - 三元运算符的意外结果
- mysql - 在 SQL 中选择不同的对
- charts - 如何获取Power BI日期切片器中选择的最小日期的对应价格
- python - Python xgb:ValueError:“feature_names 不匹配”
- php - php calendar - 从星期一开始日历
- minikube - 在本地网络服务器上安装 Eclipse Che 7.0 并从不同的机器访问
- java - 如何在java中删除链接列表的最后一个节点?
- javafx - 指定的文件夹不包含 Java 平台
- c# - 实体框架:如何为批量操作建模