本文整理汇总了C#中AsyncSubject.GetResult方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncSubject.GetResult方法的具体用法?C# AsyncSubject.GetResult怎么用?C# AsyncSubject.GetResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncSubject
的用法示例。
在下文中一共展示了AsyncSubject.GetResult方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResult_Blocking
private void GetResult_Blocking(AsyncSubject<int> s)
{
Assert.IsFalse(s.IsCompleted);
var e = new ManualResetEvent(false);
new Thread(() => { e.WaitOne(); s.OnNext(42); s.OnCompleted(); }).Start();
var y = default(int);
var t = new Thread(() => { y = s.GetResult(); });
t.Start();
while (t.ThreadState != ThreadState.WaitSleepJoin)
;
e.Set();
t.Join();
Assert.AreEqual(42, y);
Assert.IsTrue(s.IsCompleted);
}
示例2: GetResult_Blocking_Throw
private void GetResult_Blocking_Throw(AsyncSubject<int> s)
{
Assert.IsFalse(s.IsCompleted);
var e = new ManualResetEvent(false);
var ex = new Exception();
new Thread(() => { e.WaitOne(); s.OnError(ex); }).Start();
var y = default(Exception);
var t = new Thread(() =>
{
try
{
s.GetResult();
}
catch (Exception ex_)
{
y = ex_;
}
});
t.Start();
while (t.ThreadState != ThreadState.WaitSleepJoin)
;
e.Set();
t.Join();
Assert.AreSame(ex, y);
Assert.IsTrue(s.IsCompleted);
}
示例3: GetResult_Empty
public void GetResult_Empty()
{
var s = new AsyncSubject<int>();
s.OnCompleted();
ReactiveAssert.Throws<InvalidOperationException>(() => s.GetResult());
}