我想知道是否有辦法採取可觀察的流並使用* 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(我的錯誤) –