From 5ed943bca21f00d123621e0d973dcbb31c90eb04 Mon Sep 17 00:00:00 2001 From: neuecc Date: Fri, 19 Jun 2020 16:42:05 +0900 Subject: [PATCH] Add UniTask.Post --- .../UniTask/Runtime/Internal/ContinuationQueue.cs | 11 +++++++++-- .../Plugins/UniTask/Runtime/UniTask.Threading.cs | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs index 2ba5938..30bd737 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs @@ -9,7 +9,7 @@ namespace Cysharp.Threading.Tasks.Internal { const int MaxArrayLength = 0X7FEFFFFF; const int InitialSize = 16; - + readonly PlayerLoopTiming timing; SpinLock gate = new SpinLock(); @@ -173,7 +173,14 @@ namespace Cysharp.Threading.Tasks.Internal var action = actionList[i]; actionList[i] = null; - action(); + try + { + action(); + } + catch (Exception ex) + { + UnityEngine.Debug.LogException(ex); + } } { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs index 8077f60..39cd70f 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs @@ -44,6 +44,14 @@ namespace Cysharp.Threading.Tasks return new ReturnToMainThread(timing); } + /// + /// Queue the action to PlayerLoop. + /// + public static void Post(Action action, PlayerLoopTiming timing = PlayerLoopTiming.Update) + { + PlayerLoopHelper.AddContinuation(timing, action); + } + #endif public static SwitchToThreadPoolAwaitable SwitchToThreadPool()