如何检测承诺值的变化?

How to detect change in promise value?

我想轮询 returns 承诺的某些函数并检测解析值的变化。我需要以某种方式在此处添加 interval 运算符。

const observer = (newValue) => {
  console.log('Change detected', newValue);
}

Observable.fromPromise(getValue())
  .distinctUntilChanged((oldValue, newValue) => oldValue == newValue)
  .subscribe(observer);

switchMap

的典型案例
Observable.interval(1000)
  .switchMap(() => Observable.fromPromise(getValue())
  .distinctUntilChanged((oldValue, newValue) => oldValue == newValue)
  .subscribe(observer);