【发布时间】:2020-05-28 08:40:02
【问题描述】:
我想运行一个计算密集型函数,该函数依赖于 3 个 behaviorSubjects 的最新值。 有时所有科目同时更改,我不想运行 3 次计算。 这就是我现在实现它的方式。
this.subscription = merge(behaviorSubject1$, behaviorSubject2$, behaviorSubject3$)
.pipe(throttleTime(300)) //this is to avoid running the function 3 times when all subjects change simultaneously
.subscribe(() => {
const answer = getSolution(subject1$.getValue(), subject2$.getValue(), subject3$.getValue());
});
我不确定这是否是最好的方法。非常感谢任何帮助
【问题讨论】:
标签: angular rxjs observable reactive-programming behaviorsubject