【发布时间】:2016-09-05 01:20:44
【问题描述】:
我有Observable.Interval(TimeSpan.FromSeconds(1)) 和一个订阅者,它在每个时间间隔发生时检查数据库中的某些内容。但有时当我从数据库进行检查时,我想立即执行另一次检查(再次调用该订阅者,因为我知道队列中有东西)。
我已经通过在订阅者方法中将 Interval 与 while 结合起来实现了类似的效果:
Observable
.Interval(TimeSpan.FromSeconds(1))
.Sample(TimeSpan.FromSeconds(1)) //to avoid multiple 'stacked' intervals
.Subscribe(RepeatAction);
private void RepeatAction(long _)
{
bool wasSuccess;
do
{
wasSuccess = CheckingInDB(); //Long operation
} while (wasSuccess );
}
但是有没有可能用 pure 响应式来实现这种行为?
【问题讨论】:
-
SubscribeInContext方法是什么?哪里来的?
标签: c# system.reactive observable