Skip to content

Commit

Permalink
Fix WaitWhile(bool cancelImmediately = true) does not work correctly
Browse files Browse the repository at this point in the history
, and when cancelImmediately = true and canceled task remove Trakcking immediately
  • Loading branch information
neuecc committed Sep 24, 2024
1 parent f7b3c2f commit 75119ac
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -404,7 +408,13 @@ public T GetResult(short token)
finally
{
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -366,6 +370,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -475,6 +483,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -604,6 +616,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -750,6 +766,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -878,6 +898,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -1004,6 +1028,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Threading;
using Cysharp.Threading.Tasks.Internal;

Expand Down Expand Up @@ -102,6 +103,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -193,6 +198,7 @@ public static IUniTaskSource Create(Func<bool> predicate, PlayerLoopTiming timin

result.predicate = predicate;
result.cancellationToken = cancellationToken;
result.cancelImmediately = cancelImmediately;

if (cancelImmediately && cancellationToken.CanBeCanceled)
{
Expand Down Expand Up @@ -223,6 +229,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -343,6 +353,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -459,6 +473,10 @@ public U GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -598,6 +616,10 @@ public U GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public UnityEngine.Object[] GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public AsyncGPUReadbackRequest GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public void GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -384,6 +388,10 @@ public UnityEngine.Object GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -615,6 +623,10 @@ public UnityEngine.Object GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -847,6 +859,10 @@ public AssetBundle GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down Expand Up @@ -1095,6 +1111,10 @@ public UnityWebRequest GetResult(short token)
{
TryReturn();
}
else
{
TaskTracker.RemoveTracking(this);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/UniTask/Assets/Scenes/SandboxMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
using System.Linq.Expressions;



// using DG.Tweening;



public struct MyJob : IJob
{
public int loopCount;
Expand Down
Loading

0 comments on commit 75119ac

Please sign in to comment.