如何对 RX 序列进行上采样,即使其更频繁地触发?
.Sample 运算符只允许下采样:
IObservable<long> source = Observable.Interval(TimeSpan.FromMilliseconds(5000));
IObservable<long> trigger = Observable.Interval(TimeSpan.FromMilliseconds(1000));
//var triggeredSource = source.Sample(trigger);
var triggeredSource = source.Sample(TimeSpan.FromMilliseconds(1000));
source.Subscribe(Console.WriteLine);
triggeredSource.Subscribe(Console.WriteLine);
这里 triggerSource 仅每 5000 毫秒触发一次,而不是 1000 毫秒。我们想要:
source: ----a----b----c----d------
trigger: -o-o-o-o-o-o-o-o-o-o-o-o-o
result: ----aa-a-b-b-bcc-c-d-d-d-d
如何才能做到这一点?