我正在遵循教程(https://www.learnrxjs.io/operators/combination/withlatestfrom.html)中的示例:
// RxJS v6+
import { withLatestFrom, map } from 'rxjs/operators';
import { interval } from 'rxjs';
//emit every 5s
const source = interval(5000);
//emit every 1s
const secondSource = interval(1000);
const example = source.pipe(
withLatestFrom(secondSource),
map(([first, second]) => {
return `First Source (5s): ${first} Second Source (1s): ${second}`;
})
);
/*
"First Source (5s): 0 Second Source (1s): 4"
"First Source (5s): 1 Second Source (1s): 9"
"First Source (5s): 2 Second Source (1s): 14"
...
*/
const subscribe = example.subscribe(val => console.log(val));
当我使用RXJS 6.2.2,Node 8.9.4运行此代码时,我期望的是:
First Source (5s): 0 Second Source (1s): 4
First Source (5s): 1 Second Source (1s): 9
但是我得到了
First Source (5s): 0 Second Source (1s): 3
First Source (5s): 1 Second Source (1s): 8
这是为什么?