本文整理汇总了C#中Nito.AsyncEx.TaskCompletionSource.Select方法的典型用法代码示例。如果您正苦于以下问题:C# TaskCompletionSource.Select方法的具体用法?C# TaskCompletionSource.Select怎么用?C# TaskCompletionSource.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nito.AsyncEx.TaskCompletionSource
的用法示例。
在下文中一共展示了TaskCompletionSource.Select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OrderByCompletion_PropagatesFaultOnSecondCompletion
public void OrderByCompletion_PropagatesFaultOnSecondCompletion()
{
Test.Async(async () =>
{
var tcs = new TaskCompletionSource<int>[] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() };
var results = tcs.Select(x => x.Task).OrderByCompletion();
tcs[0].SetResult(13);
tcs[1].SetException(new InvalidOperationException("test message"));
await results[0];
try
{
await results[1];
}
catch (InvalidOperationException ex)
{
Assert.AreEqual("test message", ex.Message);
return;
}
Assert.Fail();
});
}
示例2: OrderByCompletion_PropagatesCancelOnSecondCompletion
public void OrderByCompletion_PropagatesCancelOnSecondCompletion()
{
Test.Async(async () =>
{
var tcs = new TaskCompletionSource<int>[] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() };
var results = tcs.Select(x => x.Task).OrderByCompletion();
tcs[0].SetResult(13);
tcs[1].SetCanceled();
await results[0];
try
{
await results[1];
}
catch (OperationCanceledException)
{
return;
}
Assert.Fail();
});
}
示例3: OrderByCompletion_OrdersByCompletion
public void OrderByCompletion_OrdersByCompletion()
{
Test.Async(async () =>
{
var tcs = new TaskCompletionSource<int>[] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() };
var results = tcs.Select(x => x.Task).OrderByCompletion();
Assert.IsFalse(results[0].IsCompleted);
Assert.IsFalse(results[1].IsCompleted);
tcs[1].SetResult(13);
var result0 = await results[0];
Assert.IsFalse(results[1].IsCompleted);
Assert.AreEqual(13, result0);
tcs[0].SetResult(17);
var result1 = await results[1];
Assert.AreEqual(13, result0);
Assert.AreEqual(17, result1);
});
}