本文整理汇总了C#中Subject.CombineLatest方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.CombineLatest方法的具体用法?C# Subject.CombineLatest怎么用?C# Subject.CombineLatest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.CombineLatest方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CombineLatest
public void CombineLatest()
{
var a = new Subject<int>();
var b = new Subject<int>();
a.OnNext(10);
b.OnNext(20);
var l = Enumerable.Empty<Unit>().Select(_ => Notification.CreateOnNext(new { x = 0, y = 0 })).ToList();
a.CombineLatest(b, (x, y) => new { x, y }).Materialize().Subscribe(x => l.Add(x));
a.OnNext(1000);
b.OnNext(2000);
l[0].Value.Is(new { x = 1000, y = 2000 });
b.OnNext(3000);
l[1].Value.Is(new { x = 1000, y = 3000 });
a.OnNext(5000);
l[2].Value.Is(new { x = 5000, y = 3000 });
a.OnCompleted();
l.Count.Is(3);
a.OnNext(1001);
l.Count.Is(3);
b.OnNext(5);
l[3].Value.Is(new { x = 5000, y = 5 });
b.OnNext(500);
l[4].Value.Is(new { x = 5000, y = 500 });
b.OnCompleted();
l[5].Kind.Is(NotificationKind.OnCompleted);
}
示例2: CombiningLatestValues
private static void CombiningLatestValues()
{
Demo.DisplayHeader("The CombineLatest operator - combines values from the observables whenever any of the observable sequences produces an element");
Subject<int> heartRate = new Subject<int>();
Subject<int> speed = new Subject<int>();
speed
.CombineLatest(heartRate,
(s, h) => String.Format("Heart:{0} Speed:{1}", h, s))
.SubscribeConsole("Metrics");
heartRate.OnNext(200);
heartRate.OnNext(201);
heartRate.OnNext(202);
speed.OnNext(30);
speed.OnNext(31);
heartRate.OnNext(203);
heartRate.OnNext(204);
}
示例3: CombineLatest4
public void CombineLatest4()
{
var a = new Subject<int>();
var b = new Subject<int>();
a.OnNext(10);
b.OnNext(20);
var l = Enumerable.Empty<Unit>().Select(_ => Notification.CreateOnNext(new { x = 0, y = 0 })).ToList();
a.CombineLatest(b, (x, y) => new { x, y }).Materialize().Subscribe(x => l.Add(x));
b.OnCompleted();
l.Count.Is(0);
a.OnNext(30);
l.Count.Is(1);
l[0].Kind.Is(NotificationKind.OnCompleted);
}
示例4: CombineLatest3
public void CombineLatest3()
{
SetScehdulerForImport();
var a = new Subject<int>();
var b = new Subject<int>();
a.OnNext(10);
b.OnNext(20);
var l = Enumerable.Empty<Unit>().Select(_ => Notification.CreateOnNext(new { x = 0, y = 0 })).ToList();
a.CombineLatest(b, (x, y) => new { x, y }).Materialize().Subscribe(x => l.Add(x));
a.OnNext(2000);
b.OnCompleted();
l.Count.Is(0);
a.OnNext(30);
l.Count.Is(1);
l[0].Kind.Is(NotificationKind.OnCompleted);
UniRx.Scheduler.SetDefaultForUnity();
}
示例5: CombineLatestCompletesWhenBothSequencesComplete
public void CombineLatestCompletesWhenBothSequencesComplete()
{
var left = new Subject<int>();
var right = new Subject<int>();
var result = left.CombineLatest(right, (l, r) => l + r).Materialize().CreateCollection();
left.OnNext(1);
left.OnCompleted();
right.OnNext(1);
right.OnCompleted();
Assert.Equal(new[] { Notification.CreateOnNext(2), Notification.CreateOnCompleted<int>() }, result);
}