changed clear loop runner queue timing in UnityEditor and run rest action when quitted

master
neuecc 2020-09-21 12:30:31 +09:00
parent 5d4a90e9bd
commit 3f18b37e5f
4 changed files with 63 additions and 21 deletions

View File

@ -70,13 +70,17 @@ namespace Cysharp.Threading.Tasks.Internal
} }
} }
public void Clear() public int Clear()
{ {
var rest = actionListCount + waitingListCount;
actionListCount = 0; actionListCount = 0;
actionList = new Action[InitialSize]; actionList = new Action[InitialSize];
waitingListCount = 0; waitingListCount = 0;
waitingList = new Action[InitialSize]; waitingList = new Action[InitialSize];
return rest;
} }
// delegate entrypoint. // delegate entrypoint.

View File

@ -48,14 +48,24 @@ namespace Cysharp.Threading.Tasks.Internal
} }
} }
public void Clear() public int Clear()
{ {
lock (arrayLock) lock (arrayLock)
{ {
var rest = 0;
for (var index = 0; index < loopItems.Length; index++) for (var index = 0; index < loopItems.Length; index++)
{ {
if (loopItems[index] != null)
{
rest++;
}
loopItems[index] = null; loopItems[index] = null;
} }
tail = 0;
return rest;
} }
} }

View File

@ -110,27 +110,30 @@ namespace Cysharp.Threading.Tasks
#if UNITY_EDITOR #if UNITY_EDITOR
EditorApplication.playModeStateChanged += (state) => EditorApplication.playModeStateChanged += (state) =>
{ {
if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.EnteredPlayMode) if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.ExitingEditMode)
{ {
return; // run rest action before clear.
} if (runner != null)
{
runner.Run();
runner.Clear();
}
if (lastRunner != null)
{
lastRunner.Run();
lastRunner.Clear();
}
if (runner != null) if (cq != null)
{ {
runner.Clear(); cq.Run();
} cq.Clear();
if (lastRunner != null) }
{ if (lastCq != null)
lastRunner.Clear(); {
} lastCq.Run();
lastCq.Clear();
if (cq != null) }
{
cq.Clear();
}
if (lastCq != null)
{
lastCq.Clear();
} }
}; };
#endif #endif

View File

@ -492,8 +492,33 @@ public class SandboxMain : MonoBehaviour
Debug.Log("Current SyncContext:" + SynchronizationContext.Current.GetType().FullName); Debug.Log("Current SyncContext:" + SynchronizationContext.Current.GetType().FullName);
} }
async UniTask QuitCheck()
{
try
{
await UniTask.Delay(TimeSpan.FromMinutes(1), cancellationToken: quitSource.Token);
}
finally
{
Debug.Log("End QuitCheck async");
}
}
CancellationTokenSource quitSource = new CancellationTokenSource();
async UniTaskVoid Start() async UniTaskVoid Start()
{ {
Debug.Log("App Start");
Application.quitting += () =>
{
Debug.Log("called quitting");
quitSource.Cancel();
};
QuitCheck().Forget();
//Expression.Lambda<Func<int>>(null).Compile(true); //Expression.Lambda<Func<int>>(null).Compile(true);
//RunStandardTaskAsync(); //RunStandardTaskAsync();