當前位置: 首頁>>代碼示例>>C#>>正文


C# BehaviorSubject.Current方法代碼示例

本文整理匯總了C#中BehaviorSubject.Current方法的典型用法代碼示例。如果您正苦於以下問題:C# BehaviorSubject.Current方法的具體用法?C# BehaviorSubject.Current怎麽用?C# BehaviorSubject.Current使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.Current方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Observable_Current_returns_latest_element

        public async Task Observable_Current_returns_latest_element()
        {
            var subject = new BehaviorSubject<int>(1);
            var asyncEnumerable = subject.Current();

            using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
            {
                subject.OnNext(2);
                subject.OnNext(3);
                subject.OnNext(4);

                Assert.True(await asyncEnumerator.MoveNext(CancellationToken.None));
                Assert.Equal(4, asyncEnumerator.Current);
            }
        }
開發者ID:ExRam,項目名稱:ExRam.Extensions,代碼行數:15,代碼來源:ObservableExtensionsTests.cs

示例2: Observable_Current_returns_elements_repeatedly

        public async Task Observable_Current_returns_elements_repeatedly()
        {
            var subject = new BehaviorSubject<int>(1);
            var asyncEnumerable = subject.Current();

            using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
            {
                for (var i = 0; i < 10; i++)
                {
                    Assert.True(await asyncEnumerator.MoveNext(CancellationToken.None));
                    Assert.Equal(1, asyncEnumerator.Current);
                }

                subject.OnNext(2);

                for (var i = 0; i < 10; i++)
                {
                    Assert.True(await asyncEnumerator.MoveNext(CancellationToken.None));
                    Assert.Equal(2, asyncEnumerator.Current);
                }
            }
        }
開發者ID:ExRam,項目名稱:ExRam.Extensions,代碼行數:22,代碼來源:ObservableExtensionsTests.cs

示例3: Observable_Current_completes_on_source_completion

        public async Task Observable_Current_completes_on_source_completion()
        {
            var subject = new BehaviorSubject<int>(1);
            var asyncEnumerable = subject.Current();

            using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
            {
                subject.OnNext(1);
                subject.OnNext(2);
                subject.OnNext(3);

                subject.OnCompleted();

                Assert.False(await asyncEnumerator.MoveNext(CancellationToken.None));
            }
        }
開發者ID:ExRam,項目名稱:ExRam.Extensions,代碼行數:16,代碼來源:ObservableExtensionsTests.cs

示例4: Observable_Current_propagates_exception

        public async Task Observable_Current_propagates_exception()
        {
            var subject = new BehaviorSubject<int>(1);
            var asyncEnumerable = subject.Current();

            using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
            {
                subject.OnNext(1);
                subject.OnNext(2);
                subject.OnNext(3);

                subject.OnError(new InvalidOperationException());

                asyncEnumerator
                    .Awaiting(_ => _.MoveNext(CancellationToken.None))
                    .ShouldThrowExactly<AggregateException>()
                    .Where(ex => ex.GetBaseException() is InvalidOperationException);
            }
        }
開發者ID:ExRam,項目名稱:ExRam.Extensions,代碼行數:19,代碼來源:ObservableExtensionsTests.cs


注:本文中的BehaviorSubject.Current方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。