我需要知道4个可观察流中的最新值何时与谓词匹配。
对于仅两个流,我可以将CombineLatest与Where一起使用。
对于n>2个流,我将如何实现这一点。
谢谢。
编辑:回答我试图实现的目标
void Main()
{
var s1 = Observable.Interval(TimeSpan.FromMilliseconds(50));
var s2 = Observable.Interval(TimeSpan.FromMilliseconds(60));
var s3 = Observable.Interval(TimeSpan.FromMilliseconds(70));
var s4 = Observable.Interval(TimeSpan.FromMilliseconds(80));
Observable.CombineLatest(s1, s2, s3, s4)
.Where(xs => xs.All(x => x > 10 && x < 20))
.Subscribe(x =>
{
x.Dump();
});
}
我认为您仍然可以使用CombineLatest,或者我可能错过了您的要求。
[TestMethod]
public void GreaterThan2StreamsCombineLatest()
{
//Arrange
var s1 = Observable.Return(1).Concat(Observable.Return(10));
var s2 = Observable.Return(2);
var s3 = Observable.Return(3);
var expected = "They're all greater than 1";
var result = string.Empty;
//Act
Observable.CombineLatest(s1, s2, s3)
.Where(xs => xs.All(x => x > 1))
.Subscribe(x =>
{
x.ToList().ForEach(Console.WriteLine);
result = "They're all greater than 1";
});
//Assert
Assert.AreEqual(expected, result);
}