mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-26 18:10:17 +00:00
call webRequest.Abort() on canceled
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
public static partial class UnityAsyncExtensions
|
public static partial class UnityAsyncExtensions
|
||||||
{
|
{
|
||||||
#region AsyncOperation
|
#region AsyncOperation
|
||||||
|
|
||||||
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
|
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
|
||||||
{
|
{
|
||||||
@@ -179,9 +179,9 @@ namespace Cysharp.Threading.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# endregion
|
#endregion
|
||||||
|
|
||||||
#region ResourceRequest
|
#region ResourceRequest
|
||||||
|
|
||||||
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest asyncOperation)
|
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest asyncOperation)
|
||||||
{
|
{
|
||||||
@@ -356,9 +356,9 @@ namespace Cysharp.Threading.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# endregion
|
#endregion
|
||||||
|
|
||||||
#region AssetBundleRequest
|
#region AssetBundleRequest
|
||||||
|
|
||||||
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest asyncOperation)
|
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest asyncOperation)
|
||||||
{
|
{
|
||||||
@@ -533,9 +533,9 @@ namespace Cysharp.Threading.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# endregion
|
#endregion
|
||||||
|
|
||||||
#region AssetBundleCreateRequest
|
#region AssetBundleCreateRequest
|
||||||
|
|
||||||
public static AssetBundleCreateRequestAwaiter GetAwaiter(this AssetBundleCreateRequest asyncOperation)
|
public static AssetBundleCreateRequestAwaiter GetAwaiter(this AssetBundleCreateRequest asyncOperation)
|
||||||
{
|
{
|
||||||
@@ -710,10 +710,10 @@ namespace Cysharp.Threading.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# endregion
|
#endregion
|
||||||
|
|
||||||
#if ENABLE_UNITYWEBREQUEST
|
#if ENABLE_UNITYWEBREQUEST
|
||||||
#region UnityWebRequestAsyncOperation
|
#region UnityWebRequestAsyncOperation
|
||||||
|
|
||||||
public static UnityWebRequestAsyncOperationAwaiter GetAwaiter(this UnityWebRequestAsyncOperation asyncOperation)
|
public static UnityWebRequestAsyncOperationAwaiter GetAwaiter(this UnityWebRequestAsyncOperation asyncOperation)
|
||||||
{
|
{
|
||||||
@@ -853,6 +853,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
|
asyncOperation.webRequest.Abort();
|
||||||
core.TrySetCanceled(cancellationToken);
|
core.TrySetCanceled(cancellationToken);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -888,7 +889,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# endregion
|
#endregion
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,8 +252,18 @@ public class SandboxMain : MonoBehaviour
|
|||||||
|
|
||||||
async UniTaskVoid Test2()
|
async UniTaskVoid Test2()
|
||||||
{
|
{
|
||||||
var r = await UniAsync("https://bing.com/");
|
try
|
||||||
Debug.Log("UNIASYNC");
|
{
|
||||||
|
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)
|
IEnumerator Test3(string url)
|
||||||
@@ -269,9 +279,9 @@ public class SandboxMain : MonoBehaviour
|
|||||||
return req;
|
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;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user