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


C# Subject.TakeLast方法代码示例

本文整理汇总了C#中Subject.TakeLast方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.TakeLast方法的具体用法?C# Subject.TakeLast怎么用?C# Subject.TakeLast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subject的用法示例。


在下文中一共展示了Subject.TakeLast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: complete_is_called_after_source_completes

        public void complete_is_called_after_source_completes()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            subject
                .TakeLast(3)
                .Subscribe(stats);

            subject.OnNext(0);
            subject.OnNext(0);
            subject.OnNext(0);
            Assert.IsFalse(stats.CompletedCalled);

            subject.OnCompleted();
            Assert.IsTrue(stats.CompletedCalled);
            Assert.AreEqual(3, stats.NextCount);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:19,代码来源:TakeLast.cs

示例2: last_count_values_are_emitted

        public void last_count_values_are_emitted()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            subject
                .TakeLast(3)
                .Subscribe(stats);

            subject.OnNext(0);
            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();
            Assert.AreEqual(3, stats.NextCount);
            Assert.AreEqual(1, stats.NextValues[0]);
            Assert.AreEqual(2, stats.NextValues[1]);
            Assert.AreEqual(3, stats.NextValues[2]);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:20,代码来源:TakeLast.cs

示例3: Run

        public static void Run()
        {
            {
            Console.WriteLine("= Skip =======");
            Observable.Range(0, 10)
              .Skip(3)
              .Subscribe(
            Console.WriteLine,
            () => Console.WriteLine("OnCompleted()"));
              }

              {
            Console.WriteLine("= Take =======");
            Observable.Range(0, 10)
              .Take(3)
              .Subscribe(
            Console.WriteLine,
            () => Console.WriteLine("OnCompleted()"));
              }

              {
            Console.WriteLine("= SkipWhile =======");
            var subject = new Subject<int>();
            subject
              .SkipWhile(i => i < 4)
              .Subscribe(
            Console.WriteLine,
            () => Console.WriteLine("OnCompleted()"));

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnNext(4);
            subject.OnNext(3);
            subject.OnNext(2);
            subject.OnNext(1);
            subject.OnCompleted();
              }

              {
            Console.WriteLine("= TakeWhile =======");
            var subject = new Subject<int>();
            subject
              .TakeWhile(i => i < 4)
              .Subscribe(
            Console.WriteLine,
            () => Console.WriteLine("OnCompleted()"));

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnNext(4);
            subject.OnNext(3);
            subject.OnNext(2);
            subject.OnNext(1);
            subject.OnCompleted();
              }

              {
            Console.WriteLine("= SkipLast =======");
            var subject = new Subject<int>();
            subject
              .SkipLast(2)
              .Subscribe(Console.WriteLine, () => Console.WriteLine("Completed"));

            Console.WriteLine("Pushing 1");
            subject.OnNext(1);
            Console.WriteLine("Pushing 2");
            subject.OnNext(2);
            Console.WriteLine("Pushing 3");
            subject.OnNext(3);
            Console.WriteLine("Pushing 4");
            subject.OnNext(4);
            subject.OnCompleted();
              }

              {
            Console.WriteLine("= TakeLast =======");
            var subject = new Subject<int>();
            subject
              .TakeLast(2)
              .Subscribe(Console.WriteLine, () => Console.WriteLine("Completed"));

            Console.WriteLine("Pushing 1");
            subject.OnNext(1);
            Console.WriteLine("Pushing 2");
            subject.OnNext(2);
            Console.WriteLine("Pushing 3");
            subject.OnNext(3);
            Console.WriteLine("Pushing 4");
            subject.OnNext(4);
            subject.OnCompleted();
              }

              {
            Console.WriteLine("= SkipUntil =======");
            var subject = new Subject<int>();
            var otherSubject = new Subject<Unit>();
            subject
              .SkipUntil(otherSubject)
//.........这里部分代码省略.........
开发者ID:pudae,项目名称:lplpl,代码行数:101,代码来源:TestSkipTake.cs

示例4: Start

            public IDisposable Start()
            {
                _clients = new Queue<SocketClient>(arguments.ConnectionLimit);
                var connections = new Subject<SocketClient>();
                EventHandler connecthandler = (s, args) => connections.OnNext(s as SocketClient);

                long bytesSent = 0;

                EventHandler<long> onsend = (s, i) =>
                {
                    bytesSent += i;
                };

                Action connect = () =>
                {
                    var client = new SocketClient(arguments.Server, arguments.Port);
                    client.OnConnected += connecthandler;
                    client.OnSend += onsend;
                    client.ConnectAsync();
                    lock (_clients)
                    {
                        _clients.Enqueue(client);
                    }
                };

                //Ping(clients);

                int count = 0;
                var resource = connections.Subscribe(_ =>
                {
                    count++;
                    if (count < arguments.ConnectionLimit)
                    {
                        connect();
                    }
                    else
                    {
                        connections.OnCompleted();
                    }
                },
                    () =>
                    {
                        Console.WriteLine("client: Active {0} connections", count);
                        Console.WriteLine("Sending Messages at a rate of {0} messages/sec", arguments.MessageRate);
                        Observable.Interval(TimeSpan.FromSeconds(1))
                                 .Subscribe(_ =>
                                 {
                                     for (int i = 0; i < arguments.MessageRate; i++)
                                     {
                                         MessageNextClient();
                                     }
                                 });
                    });

                connect(); //Kick off the process
                long previousConnects = 0;
                const int pollTimeSeconds = 2;
                Observable.Interval(TimeSpan.FromSeconds(pollTimeSeconds))
                    .TakeWhile(_ => count < arguments.ConnectionLimit)
                    .Subscribe(_ =>
                    {
                        var diff = count - previousConnects;
                        Console.WriteLine("client: Active: {0} \tconnects/sec: {1}  \tPending: {2}",
                            count,
                            diff / pollTimeSeconds,
                            arguments.ConnectionLimit - count);
                        previousConnects = count;
                    });

                long previous = 0;
                connections.TakeLast(1).SelectMany(_ => Observable.Interval(TimeSpan.FromSeconds(1)))
                  .Subscribe(_ =>
                  {
                      var diff = bytesSent - previous;
                      Console.WriteLine("client: Active: {0} \tMsg/sec: {1} \tTransferRate: {2} \tTotalTransfered: {3}",
                          _clients.Count,
                          diff / messageSize,
                          diff,
                          bytesSent);
                      previous = bytesSent;
                  });

                return resource;
            }
开发者ID:headinthebox,项目名称:IoFx,代码行数:84,代码来源:ClientManager.cs


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