call webRequest.Abort() on canceled
parent
8a56838111
commit
7cce0f48e5
|
@ -853,6 +853,7 @@ namespace Cysharp.Threading.Tasks
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
asyncOperation.webRequest.Abort();
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -252,9 +252,19 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
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");
|
||||
}
|
||||
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