当前位置: 首页>>代码示例>>C#>>正文


C# Subject.CombineLatest方法代码示例

本文整理汇总了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);
        }
开发者ID:MighteeCactus,项目名称:UniRx,代码行数:35,代码来源:Observable.ConcatTest.cs

示例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);
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:20,代码来源:Program.cs

示例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);
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:18,代码来源:UnitTests.cs

示例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();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:17,代码来源:TestImporter.cs

示例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);
            }
开发者ID:mdabbagh88,项目名称:ReactiveMarrow,代码行数:15,代码来源:ObservableExtensionsTest.cs


注:本文中的Subject.CombineLatest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。