Use innerException for Task.AsUniTask
parent
4c3d6938ed
commit
8eac07ad24
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests
|
||||
{
|
||||
public class TaskExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task PropagateException()
|
||||
{
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
||||
{
|
||||
await ThrowAsync().AsUniTask();
|
||||
});
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
||||
{
|
||||
await ThrowOrValueAsync().AsUniTask();
|
||||
});
|
||||
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
||||
{
|
||||
await Task.WhenAll(ThrowAsync(), ThrowAsync(), ThrowAsync());
|
||||
});
|
||||
}
|
||||
|
||||
async Task ThrowAsync()
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
async Task<int> ThrowOrValueAsync()
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ namespace Cysharp.Threading.Tasks
|
|||
p.TrySetCanceled();
|
||||
break;
|
||||
case TaskStatus.Faulted:
|
||||
p.TrySetException(x.Exception);
|
||||
p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception);
|
||||
break;
|
||||
case TaskStatus.RanToCompletion:
|
||||
p.TrySetResult(x.Result);
|
||||
|
@ -58,7 +58,7 @@ namespace Cysharp.Threading.Tasks
|
|||
p.TrySetCanceled();
|
||||
break;
|
||||
case TaskStatus.Faulted:
|
||||
p.TrySetException(x.Exception);
|
||||
p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception);
|
||||
break;
|
||||
case TaskStatus.RanToCompletion:
|
||||
p.TrySetResult();
|
||||
|
|
Loading…
Reference in New Issue