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


C# BehaviorSubject.Subscribe方法代码示例

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


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

示例1: BehaviourSubject

 ///<summary>
 ///With BehaviourSubject<T> ,the subscriber will only get all the last publication made
 ///Simply, BehaviourSubject has a one value buffer. Hence, it requires a default value.
 ///</summary>
 private static void BehaviourSubject()
 {
     var subject = new BehaviorSubject<string>("Rx");
         subject.OnNext("a");
         var d = subject.Subscribe(x => Console.WriteLine("Subscritipon 1 : " + x));
         subject.OnNext("b");
        // var d = subject.Subscribe(x => Console.WriteLine("Subscritipon 1 : " + x));
         d.Dispose();
         subject.OnNext("c");
         subject.Subscribe(x => Console.WriteLine("Subscritipon 2 : " + x));
 }
开发者ID:cypherwars,项目名称:ReactiveExtensions,代码行数:15,代码来源:Program.cs

示例2: live_values_are_sent_through_scheduler

        public void live_values_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.Subscribe(stats);

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnCompleted();

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(2, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(3, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1, 2 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:34,代码来源:BehaviorSubjectFixture.cs

示例3: BehaviorSubjectExample3

 public static void BehaviorSubjectExample3()
 {
     var subject = new BehaviorSubject<string>("a");
     subject.OnNext("b");
     subject.Subscribe(Console.WriteLine);
     subject.OnNext("c");
     subject.OnNext("d");
 }
开发者ID:JonDouglas,项目名称:ReactivePlayground,代码行数:8,代码来源:Program.cs

示例4: RedisLogger

        internal RedisLogger(string key, ILog log, IRedisConnectionFactory redisConnectionFactory)
        {
            this.key = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", log.Logger.Name, key);
            this.log = log;
            this.messagesSubject = new ReplaySubject<Tuple<string, string>>(100, TimeSpan.FromSeconds(5));
            this.retry = new BehaviorSubject<bool>(false);

            var redisOnConnectionAction = new Action<Task<RedisConnection>>(task =>
            {
                if (task.IsCompleted && !task.IsFaulted)
                {
                    Interlocked.CompareExchange<RedisConnection>(ref this.redisConnection, task.Result, null);
                    subscription = messagesSubject.TakeUntil(retry.Skip(1)).Subscribe((item) => 
                        {
                            redisConnection.Publish(item.Item1, item.Item2).ContinueWith(taskWithException =>
                                {
                                    taskWithException.Exception.Handle(ex => true);
                                }, TaskContinuationOptions.OnlyOnFaulted);
                        });
                }
            });

            var redisOnErrorAction = new Action<ErrorEventArgs>(ex =>
                {
                    if (ex.IsFatal)
                    {
                        retry.OnNext(true);
                        Interlocked.Exchange<RedisConnection>(ref this.redisConnection, null);
                    }
                });

            Action subscribeAction = () =>
            {
                var connectionTask = redisConnectionFactory.CreateRedisConnection();
                connectionTask.ContinueWith(taskConnection =>
                    {
                        if (!taskConnection.IsFaulted)
                        {
                            taskConnection.ContinueWith(redisOnConnectionAction);
                            taskConnection.Result.Error += (_, err) => redisOnErrorAction(err);
                        }
                        else
                        {
                            taskConnection.Exception.Handle(_ => true);
                            this.retry.OnNext(true);
                        }
                    });
            };

            retry.Subscribe(val =>
                {
                    if (val)
                        Observable.Timer(TimeSpan.FromSeconds(10)).Subscribe(_ => subscribeAction()); 
                    else
                        subscribeAction();
                });
        }
开发者ID:g-un--,项目名称:log4net.redis,代码行数:57,代码来源:RedisLogger.cs

示例5: Example4

 static void Example4()
 {
     var subject = new BehaviorSubject<string>("a");
       subject.OnNext("b");
       subject.OnNext("c");
       subject.OnNext("d");
       subject.OnCompleted();
       subject.Subscribe(Console.WriteLine);
 }
开发者ID:pudae,项目名称:lplpl,代码行数:9,代码来源:TestBehaviorSubject.cs

示例6: Start

        private void Start()
        {
            //BehaviorSubjectは初期値を設定できる
            behaviorSubject = new BehaviorSubject<int>(0);

            /*
            OnNext → Subscribe と実行し、Subscribeした瞬間に直前の値が発行されることを確認しよう
            */

            // Subscribeボタンが押されたらSubjectをSubscribeしてresultTextに表示する
            subscribeButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (behaviorSubject != null)
                {
                    behaviorSubject.Subscribe(
                        time => resultText.text += time.ToString() + " ", //OnNext
                        () => resultText.text += "OnCompleted "); //OnCompleted
                }
            });

            // OnNextボタンが押されたら今が何度目のOnNextであるかを発行する
            onNextButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (behaviorSubject != null)
                {
                    behaviorSubject.OnNext(++onNextCount);
                }
            });

            // OnCompletedボタンが押されたらOnCompletedを発行する
            onCompletedButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (behaviorSubject != null)
                {
                    behaviorSubject.OnCompleted();
                }
            });

            // Resetボタンが押されたら全体を初期化する
            resetButton.OnClickAsObservable().Subscribe(_ =>
            {
                if (behaviorSubject != null)
                {
                    behaviorSubject.OnCompleted();
                }
                behaviorSubject = new BehaviorSubject<int>(0);
                resultText.text = "";
                onNextCount = 0;
            });
        }
开发者ID:TORISOUP,项目名称:UniRxWorkBook,代码行数:50,代码来源:Lesson_2_BehaviorSubject.cs

示例7: errors_are_sent_through_scheduler

        public void errors_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsFalse(stats.ErrorCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:17,代码来源:BehaviorSubjectFixture.cs

示例8: Main

        static void Main(string[] args)
        {
            var serviceClient = new JsonRestClientAsync("http://g-un--:1337/");
            var responseSubject = new BehaviorSubject<Unit>(Unit.Default);

            responseSubject.Subscribe(_ =>
                {
                    serviceClient.PostAsync<ResourceResponse>(
                        "/async",
                        new ResourceRequest()
                        {
                            ResourceKey = Guid.NewGuid().ToString()
                        },
                        response =>
                        {
                            Console.WriteLine("Data received");
                            Console.WriteLine(response.ResourceData);
                            responseSubject.OnNext(Unit.Default);
                        },
                        (response, ex) =>
                        {
                            Console.WriteLine("Exception on calling service post method");
                            Console.WriteLine(ex);
                            responseSubject.OnCompleted();
                        });
                });

            Observable.Interval(TimeSpan.FromSeconds(1))
                .Subscribe(_ =>
                    {
                        var newClient = new JsonRestClientAsync("http://g-un--:1337/");
                        newClient.PutAsync<object>(
                            "/async",
                            new ResourceRequest() { ResourceKey = Guid.NewGuid().ToString() },
                            response =>
                            {
                                Console.WriteLine("Put was sent!");
                            },
                            (response, exception) =>
                            {
                                Console.WriteLine(exception);
                            });
                    });

            Console.ReadLine();
        }
开发者ID:g-un--,项目名称:ServiceStackTests,代码行数:46,代码来源:Program.cs

示例9: complete_is_sent_through_scheduler

        public void complete_is_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnCompleted();

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(0, stats.NextCount);
            Assert.IsTrue(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:18,代码来源:BehaviorSubjectFixture.cs

示例10: HasObservers

        public void HasObservers()
        {
            var s = new BehaviorSubject<int>(42);
            Assert.IsFalse(s.HasObservers);

            var d1 = s.Subscribe(_ => { });
            Assert.IsTrue(s.HasObservers);

            d1.Dispose();
            Assert.IsFalse(s.HasObservers);

            var d2 = s.Subscribe(_ => { });
            Assert.IsTrue(s.HasObservers);

            var d3 = s.Subscribe(_ => { });
            Assert.IsTrue(s.HasObservers);

            d2.Dispose();
            Assert.IsTrue(s.HasObservers);

            d3.Dispose();
            Assert.IsFalse(s.HasObservers);
        }
开发者ID:Balharmander123,项目名称:Rx.NET,代码行数:23,代码来源:BehaviorSubjectTest.cs

示例11: replays_error_sequence

        public void replays_error_sequence()
        {
            BehaviorSubject<int> subject = new BehaviorSubject<int>(0);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:12,代码来源:BehaviorSubjectFixture.cs

示例12: BehaviorSubjectExample

 public static void BehaviorSubjectExample()
 {
     //Need to provide a default value.
     var subject = new BehaviorSubject<string>("a");
     subject.Subscribe(Console.WriteLine);
 }
开发者ID:JonDouglas,项目名称:ReactivePlayground,代码行数:6,代码来源:Program.cs

示例13: replays_no_values_when_complete

        public void replays_no_values_when_complete()
        {
            BehaviorSubject<int> subject = new BehaviorSubject<int>(0);

            StatsObserver<int> stats = new StatsObserver<int>();

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

            subject.Subscribe(stats);

            Assert.AreEqual(0, stats.NextCount);
            Assert.IsTrue(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:16,代码来源:BehaviorSubjectFixture.cs

示例14: replays_no_values_when_errored

        public void replays_no_values_when_errored()
        {
            BehaviorSubject<int> subject = new BehaviorSubject<int>(0);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.AreEqual(0, stats.NextCount);
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:16,代码来源:BehaviorSubjectFixture.cs

示例15: replays_empty_sequence

        public void replays_empty_sequence()
        {
            BehaviorSubject<int> subject = new BehaviorSubject<int>(0);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnCompleted();

            subject.Subscribe(stats);

            Assert.AreEqual(0, stats.NextCount);
            Assert.IsTrue(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:13,代码来源:BehaviorSubjectFixture.cs


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