From 768fd16e6065149dfb83c132efef3273cfa6aba9 Mon Sep 17 00:00:00 2001 From: neuecc Date: Thu, 3 Mar 2022 07:32:15 +0900 Subject: [PATCH] UniTask,Run obsolete --- .../Plugins/UniTask/Runtime/UniTask.Run.cs | 229 ++---------------- src/UniTask/Assets/Scenes/SandboxMain.cs | 3 +- 2 files changed, 25 insertions(+), 207 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Run.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Run.cs index 173b355..ac3e795 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Run.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Run.cs @@ -9,237 +9,56 @@ namespace Cysharp.Threading.Tasks { #region OBSOLETE_RUN - // Run is a confusing name, use only RunOnThreadPool in the future. - - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Action action, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Action action, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - action(); - } - finally - { - await UniTask.Yield(); - } - } - else - { - action(); - } - - cancellationToken.ThrowIfCancellationRequested(); + return RunOnThreadPool(action, configureAwait, cancellationToken); } - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Action action, object state, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Action action, object state, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - action(state); - } - finally - { - await UniTask.Yield(); - } - } - else - { - action(state); - } - - cancellationToken.ThrowIfCancellationRequested(); + return RunOnThreadPool(action, state, configureAwait, cancellationToken); } - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Func action, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Func action, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - await action(); - } - finally - { - await UniTask.Yield(); - } - } - else - { - await action(); - } - - cancellationToken.ThrowIfCancellationRequested(); + return RunOnThreadPool(action, configureAwait, cancellationToken); } - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Func action, object state, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Func action, object state, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - await action(state); - } - finally - { - await UniTask.Yield(); - } - } - else - { - await action(state); - } - - cancellationToken.ThrowIfCancellationRequested(); + return RunOnThreadPool(action, state, configureAwait, cancellationToken); } - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Func func, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Func func, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - return func(); - } - finally - { - await UniTask.Yield(); - cancellationToken.ThrowIfCancellationRequested(); - } - } - else - { - return func(); - } + return RunOnThreadPool(func, configureAwait, cancellationToken); } - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Func> func, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Func> func, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - return await func(); - } - finally - { - cancellationToken.ThrowIfCancellationRequested(); - await UniTask.Yield(); - cancellationToken.ThrowIfCancellationRequested(); - } - } - else - { - var result = await func(); - cancellationToken.ThrowIfCancellationRequested(); - return result; - } + return RunOnThreadPool(func, configureAwait, cancellationToken); } - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Func func, object state, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Func func, object state, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - return func(state); - } - finally - { - await UniTask.Yield(); - cancellationToken.ThrowIfCancellationRequested(); - } - } - else - { - return func(state); - } + return RunOnThreadPool(func, state, configureAwait, cancellationToken); } - /// [Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)). - public static async UniTask Run(Func> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default) + [Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")] + public static UniTask Run(Func> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default) { - cancellationToken.ThrowIfCancellationRequested(); - - await UniTask.SwitchToThreadPool(); - - cancellationToken.ThrowIfCancellationRequested(); - - if (configureAwait) - { - try - { - return await func(state); - } - finally - { - cancellationToken.ThrowIfCancellationRequested(); - await UniTask.Yield(); - cancellationToken.ThrowIfCancellationRequested(); - } - } - else - { - var result = await func(state); - cancellationToken.ThrowIfCancellationRequested(); - return result; - } + return RunOnThreadPool(func, state, configureAwait, cancellationToken); } #endregion - /// Run action on the threadPool and return to main thread if configureAwait = true. public static async UniTask RunOnThreadPool(Action action, bool configureAwait = true, CancellationToken cancellationToken = default) { diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 175e024..f665b75 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -564,8 +564,7 @@ public class SandboxMain : MonoBehaviour - - + // TestAsync(cts.Token).Forget();