From f760a2ae7846a5d88f0db8e347fe6e44759ef8a2 Mon Sep 17 00:00:00 2001 From: adrian-bio <128482408+adrian-bio@users.noreply.github.com> Date: Tue, 21 Mar 2023 13:12:46 +0100 Subject: [PATCH] Add requested stop all method https://github.com/Cysharp/UniTask/issues/386 Original fix by fsener in the initial comment of the issue --- .../UniTask/Runtime/PlayerLoopHelper.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs index 538fc01..4495947 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopHelper.cs @@ -509,6 +509,25 @@ namespace Cysharp.Threading.Tasks } q.Enqueue(continuation); } + + public static void StopAll() + { + IsEditorApplicationQuitting = true; + + if (runners != null) { + for (var i = 0; i < runners.Length; i++) { + runners[i].Clear(); + } + } + + if (yielders != null) { + for (var i = 0; i < yielders.Length; i++) { + yielders[i].Clear(); + } + } + + IsEditorApplicationQuitting = false; + } // Diagnostics helper