我想知道是否有办法采取可观察的流并使用* While运算符,特别是TakeWhile,SkipWhile和BufferWhile,以便它们的订阅者不会收到一个.OnComplete当bool'while'条件满员时?“永不停息”不经意间,BufferWhile和SkipWhile RX.Net序列
当我开始使用.TakeWhile/SkipWhile和BufferWhile运算符时,我认为它们不会终止/ .OnComplete(),但仅在布尔条件满足时才会发出(不)。
它可能会更有意义用一个例子:
我有指示,即一个实例是否忙或不和数据的可观察到的流的布尔标志:
private bool IsBusy { get;set; }
private bool IgnoreChanges { get;set; }
private IObservable<int> Producer { get;set; }
private IDisposable ConsumerSubscription { get;set; }
..和使用/设置在RX流(多个)类似的(简化的)
private void SetupRx()
{
ConsumerSubscription = Producer
.SkipWhile(_ => IgnoreChanges == true) // Drop the producer's stream of ints whenever the IgnoreChanges flag is set to true, but forward them whenever the IgnoreChanges flag is set to false
.BufferWhile(_ => IsBusy == true) // for all streamed instances buffer them as long as we are busy handling the previous one(s)
.Subscribe(i => DoSomething(i));
}
private void DoSomething(int i)
{
try
{
IsBusy = true;
// ... do something
}
finally
{
IsBusy = false;
}
}
的.SkipeWhile/.BufferWhile不应完整/的onComplete(..)每当IsBusy/IgnoreChanges标志SWI从真到假再回来,但保持流活着。
这是不知何故可以用RX.Net开箱即可和/或有人知道如何做到这一点?
只是为了澄清,RX.net中没有BufferWhile(我的错误) –