call webRequest.Abort() on canceled

master
neuecc 2020-05-25 09:54:26 +09:00
parent 8a56838111
commit 7cce0f48e5
2 changed files with 30 additions and 19 deletions

View File

@ -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;
} }

View File

@ -252,9 +252,19 @@ public class SandboxMain : MonoBehaviour
async UniTaskVoid Test2() async UniTaskVoid Test2()
{ {
var r = await UniAsync("https://bing.com/"); try
{
var cts = new CancellationTokenSource();
var r = UniAsync("https://bing.com/", cts.Token);
cts.Cancel();
await r;
Debug.Log("UNIASYNC"); 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;
} }