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