为什么在这里打印subject.onNext(3)?

时间:2019-02-09 07:50:17

标签: rxjs

在这段代码中,为什么在我设置subject.sample(500)但setTimeout(200)时首先打印subject.onNext(3)?

const Rx = require('rx');

const subject = new Rx.Subject();

const sampleObservable = subject.sample(500);

sampleObservable.subscribe(
    data => console.log(data),
    error => console.log(error),
    () => console.log('FINISHED')
);

subject.onNext(0);
subject.onNext(1);

setTimeout(() => {
    subject.onNext(2);
    subject.onNext(3);
    subject.onCompleted();
}, 200);

0 个答案:

没有答案