call webRequest.Abort() on canceled
parent
8a56838111
commit
7cce0f48e5
|
@ -13,7 +13,7 @@ namespace Cysharp.Threading.Tasks
|
|||
{
|
||||
public static partial class UnityAsyncExtensions
|
||||
{
|
||||
#region AsyncOperation
|
||||
#region AsyncOperation
|
||||
|
||||
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ namespace Cysharp.Threading.Tasks
|
|||
try
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
|
||||
|
||||
core.GetResult(token);
|
||||
}
|
||||
finally
|
||||
|
@ -179,9 +179,9 @@ namespace Cysharp.Threading.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
# endregion
|
||||
#endregion
|
||||
|
||||
#region ResourceRequest
|
||||
#region ResourceRequest
|
||||
|
||||
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest asyncOperation)
|
||||
{
|
||||
|
@ -288,7 +288,7 @@ namespace Cysharp.Threading.Tasks
|
|||
try
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
|
||||
|
||||
return core.GetResult(token);
|
||||
}
|
||||
finally
|
||||
|
@ -356,9 +356,9 @@ namespace Cysharp.Threading.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
# endregion
|
||||
#endregion
|
||||
|
||||
#region AssetBundleRequest
|
||||
#region AssetBundleRequest
|
||||
|
||||
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest asyncOperation)
|
||||
{
|
||||
|
@ -465,7 +465,7 @@ namespace Cysharp.Threading.Tasks
|
|||
try
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
|
||||
|
||||
return core.GetResult(token);
|
||||
}
|
||||
finally
|
||||
|
@ -533,9 +533,9 @@ namespace Cysharp.Threading.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
# endregion
|
||||
#endregion
|
||||
|
||||
#region AssetBundleCreateRequest
|
||||
#region AssetBundleCreateRequest
|
||||
|
||||
public static AssetBundleCreateRequestAwaiter GetAwaiter(this AssetBundleCreateRequest asyncOperation)
|
||||
{
|
||||
|
@ -642,7 +642,7 @@ namespace Cysharp.Threading.Tasks
|
|||
try
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
|
||||
|
||||
return core.GetResult(token);
|
||||
}
|
||||
finally
|
||||
|
@ -710,10 +710,10 @@ namespace Cysharp.Threading.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
# endregion
|
||||
#endregion
|
||||
|
||||
#if ENABLE_UNITYWEBREQUEST
|
||||
#region UnityWebRequestAsyncOperation
|
||||
#region UnityWebRequestAsyncOperation
|
||||
|
||||
public static UnityWebRequestAsyncOperationAwaiter GetAwaiter(this UnityWebRequestAsyncOperation asyncOperation)
|
||||
{
|
||||
|
@ -820,7 +820,7 @@ namespace Cysharp.Threading.Tasks
|
|||
try
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
|
||||
|
||||
return core.GetResult(token);
|
||||
}
|
||||
finally
|
||||
|
@ -853,6 +853,7 @@ namespace Cysharp.Threading.Tasks
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
asyncOperation.webRequest.Abort();
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
@ -888,7 +889,7 @@ namespace Cysharp.Threading.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
# endregion
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -252,8 +252,18 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
async UniTaskVoid Test2()
|
||||
{
|
||||
var r = await UniAsync("https://bing.com/");
|
||||
Debug.Log("UNIASYNC");
|
||||
try
|
||||
{
|
||||
var cts = new CancellationTokenSource();
|
||||
var r = UniAsync("https://bing.com/", cts.Token);
|
||||
cts.Cancel();
|
||||
await r;
|
||||
Debug.Log("UNIASYNC");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("Canceled");
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Test3(string url)
|
||||
|
@ -269,9 +279,9 @@ public class SandboxMain : MonoBehaviour
|
|||
return req;
|
||||
}
|
||||
|
||||
static async UniTask<UnityWebRequest> UniAsync(string url)
|
||||
static async UniTask<UnityWebRequest> UniAsync(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
var req = await UnityWebRequest.Get(url).SendWebRequest();
|
||||
var req = await UnityWebRequest.Get(url).SendWebRequest().WithCancellation(cancellationToken);
|
||||
return req;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue