当我在breakpoint
或current
上放置normal
时,会调用它们。但是,如果我将breakpoint
放在我CombineLatest
下面的行上,则永远不会调用它。
FastPeriod
= 60秒。 SlowPeriod
= 120秒。
不确定我做错了什么。
public class SpikeIndicator : IDisposable, IIndicator
{
....
public IObservable<IndicatorValues> Stream { get; private set; }
private void IntializeSpikeStream()
{
var current = Observable.Interval(TimeSpan.FromSeconds(FastPeriod))
.Select(_ => GetLastPrice());
var normal = Observable.Interval(TimeSpan.FromSeconds(SlowPeriod))
.Select(_ => GetLastPrice()).Delay(TimeSpan.FromSeconds(FastPeriod));
var stream = current.CombineLatest(normal, (a, b) => (a - b) / a)
.Where(diffPercent => diffPercent != PercentDiff)
.Select(ratePercent => new SpikeIndicatorValues { PercentRate = ratePercent }).Publish();
spikeSubscription = stream.Connect();
Stream = stream;
}
public void Dispose()
{
spikeSubscription?.Dispose();
}
public IObservable<IndicatorValues> GetObservable()
{
return this.Stream;
}
...
}
答案 0 :(得分:1)
想出来。不确定我需要多少这些改变,但这是有效的。
private void IntializeSpikeStream()
{
var current = Observable.Interval(TimeSpan.FromSeconds(FastPeriod))
.Select(_ => GetLastPrice()).Publish();
var normal = Observable.Interval(TimeSpan.FromSeconds(SlowPeriod))
.Select(_ => GetLastPrice()).Delay(TimeSpan.FromSeconds(FastPeriod)).Publish();
ts1Subscription1 = current.Connect();
ts1Subscription2 = normal.Connect();
var stream = current.CombineLatest(normal, (a, b) => (a - b) / a)
.Where(diffPercent => diffPercent != PercentDiff)
.Select(ratePercent => new SpikeIndicatorValues { PercentRate = ratePercent }).Publish();
spikeSubscription = stream.Connect();
Stream = stream;
}
public void Dispose()
{
spikeSubscription?.Dispose();
ts1Subscription1?.Dispose();
ts1Subscription2?.Dispose();
}