本文整理匯總了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);
}
}
示例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);
}
}
}
示例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));
}
}
示例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);
}
}