diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index 17619f8..a58df9a 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -133,7 +133,7 @@ namespace Cysharp.Threading.Tasks /// public static Action Action(Func asyncAction) { - return AsyncAction.Create(asyncAction); + return () => asyncAction().Forget(); } /// @@ -141,7 +141,7 @@ namespace Cysharp.Threading.Tasks /// public static Action Action(Func asyncAction, CancellationToken cancellationToken) { - return AsyncActionWithCancellation.Create(asyncAction, cancellationToken); + return () => asyncAction(cancellationToken).Forget(); } #if UNITY_2018_3_OR_NEWER @@ -152,7 +152,7 @@ namespace Cysharp.Threading.Tasks /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return AsyncUnityAction.Create(asyncAction); + return () => asyncAction().Forget(); } /// @@ -161,7 +161,7 @@ namespace Cysharp.Threading.Tasks /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) { - return AsyncUnityActionWithCancellation.Create(asyncAction, cancellationToken); + return () => asyncAction(cancellationToken).Forget(); } #endif @@ -260,194 +260,6 @@ namespace Cysharp.Threading.Tasks return task.Status; } } - - sealed class AsyncAction : ITaskPoolNode - { - static TaskPool pool; - - public AsyncAction NextNode { get; set; } - - static AsyncAction() - { - TaskPool.RegisterSizeGetter(typeof(AsyncAction), () => pool.Size); - } - - readonly Action runDelegate; - Func voidAction; - - AsyncAction() - { - runDelegate = Run; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Action Create(Func voidAction) - { - if (!pool.TryPop(out var item)) - { - item = new AsyncAction(); - } - - item.voidAction = voidAction; - return item.runDelegate; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - void Run() - { - var call = voidAction; - voidAction = null; - if (call != null) - { - pool.TryPush(this); - call.Invoke(); - } - } - } - - sealed class AsyncActionWithCancellation : ITaskPoolNode - { - static TaskPool pool; - - public AsyncActionWithCancellation NextNode { get; set; } - - static AsyncActionWithCancellation() - { - TaskPool.RegisterSizeGetter(typeof(AsyncActionWithCancellation), () => pool.Size); - } - - readonly Action runDelegate; - CancellationToken cancellationToken; - Func voidAction; - - AsyncActionWithCancellation() - { - runDelegate = Run; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Action Create(Func voidAction, CancellationToken cancellationToken) - { - if (!pool.TryPop(out var item)) - { - item = new AsyncActionWithCancellation(); - } - - item.voidAction = voidAction; - item.cancellationToken = cancellationToken; - return item.runDelegate; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - void Run() - { - var call = voidAction; - var ct = cancellationToken; - voidAction = null; - cancellationToken = default; - if (call != null) - { - pool.TryPush(this); - call.Invoke(ct); - } - } - } - -#if UNITY_2018_3_OR_NEWER - - sealed class AsyncUnityAction : ITaskPoolNode - { - static TaskPool pool; - - public AsyncUnityAction NextNode { get; set; } - - static AsyncUnityAction() - { - TaskPool.RegisterSizeGetter(typeof(AsyncUnityAction), () => pool.Size); - } - - readonly UnityEngine.Events.UnityAction runDelegate; - Func voidAction; - - AsyncUnityAction() - { - runDelegate = Run; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static UnityEngine.Events.UnityAction Create(Func voidAction) - { - if (!pool.TryPop(out var item)) - { - item = new AsyncUnityAction(); - } - - item.voidAction = voidAction; - return item.runDelegate; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - void Run() - { - var call = voidAction; - voidAction = null; - if (call != null) - { - pool.TryPush(this); - call.Invoke(); - } - } - } - - sealed class AsyncUnityActionWithCancellation : ITaskPoolNode - { - static TaskPool pool; - - public AsyncUnityActionWithCancellation NextNode { get; set; } - - static AsyncUnityActionWithCancellation() - { - TaskPool.RegisterSizeGetter(typeof(AsyncUnityActionWithCancellation), () => pool.Size); - } - - readonly UnityEngine.Events.UnityAction runDelegate; - CancellationToken cancellationToken; - Func voidAction; - - AsyncUnityActionWithCancellation() - { - runDelegate = Run; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static UnityEngine.Events.UnityAction Create(Func voidAction, CancellationToken cancellationToken) - { - if (!pool.TryPop(out var item)) - { - item = new AsyncUnityActionWithCancellation(); - } - - item.voidAction = voidAction; - item.cancellationToken = cancellationToken; - return item.runDelegate; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - void Run() - { - var call = voidAction; - var ct = cancellationToken; - voidAction = null; - cancellationToken = default; - if (call != null) - { - pool.TryPush(this); - call.Invoke(ct); - } - } - } - -#endif } internal static class CompletedTasks diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 27d2979..28326be 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -383,7 +383,11 @@ public class SandboxMain : MonoBehaviour //{ - + okButton.onClick.AddListener(UniTask.UnityAction(async () => + { + await UniTask.Yield(); + Debug.Log("Yeha"); + })); //}).Forget();