From ec0123eec7410fb2963fc7d5ceb505d95ed60c81 Mon Sep 17 00:00:00 2001 From: neuecc Date: Fri, 22 May 2020 21:42:23 +0900 Subject: [PATCH] rename UniTask.VoidAction -> UniTask.Action, UniTask.VoidUnityAction -> UniTask.UnityAction, there return type Func -> Func --- .../UniTask/Runtime/UniTask.Factory.cs | 59 +++++++++++++++---- src/UniTask/Assets/Scenes/SandboxMain.cs | 13 +++- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index 75e3cea..4a4d953 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -105,34 +105,67 @@ namespace Cysharp.Threading.Tasks /// helper of create add UniTaskVoid to delegate. /// For example: FooEvent += () => UniTask.Void(async () => { /* */ }) /// - public static void Void(Func asyncAction) + public static void Void(Func asyncAction) { asyncAction().Forget(); } - public static Action VoidAction(Func asyncAction) + /// + /// helper of create add UniTaskVoid to delegate. + /// + public static void Void(Func asyncAction, CancellationToken cancellationToken) { - return () => Void(asyncAction); + asyncAction(cancellationToken).Forget(); } -#if UNITY_2018_3_OR_NEWER - - public static UnityEngine.Events.UnityAction VoidUnityAction(Func asyncAction) - { - return () => Void(asyncAction); - } - -#endif - /// /// helper of create add UniTaskVoid to delegate. /// For example: FooEvent += (sender, e) => UniTask.Void(async arg => { /* */ }, (sender, e)) /// - public static void Void(Func asyncAction, T state) + public static void Void(Func asyncAction, T state) { asyncAction(state).Forget(); } + /// + /// helper of create add UniTaskVoid to delegate. + /// For example: FooAction = UniTask.Action(async () => { /* */ }) + /// + public static Action Action(Func asyncAction) + { + return () => asyncAction().Forget(); + } + + /// + /// helper of create add UniTaskVoid to delegate. + /// + public static Action Action(Func asyncAction, CancellationToken cancellationToken) + { + return () => asyncAction(cancellationToken).Forget(); + } + +#if UNITY_2018_3_OR_NEWER + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For exampe: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + { + return () => asyncAction().Forget(); + } + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For exampe: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy())) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) + { + return () => asyncAction(cancellationToken).Forget(); + } + +#endif + /// /// Defer the task creation just before call await. /// diff --git a/src/UniTask/Assets/Scenes/SandboxMain.cs b/src/UniTask/Assets/Scenes/SandboxMain.cs index 9898ae7..64a4e35 100644 --- a/src/UniTask/Assets/Scenes/SandboxMain.cs +++ b/src/UniTask/Assets/Scenes/SandboxMain.cs @@ -142,7 +142,7 @@ public class SandboxMain : MonoBehaviour { // State Hp { get; } - + public Model() @@ -173,7 +173,7 @@ public class SandboxMain : MonoBehaviour void Start2() { - + } @@ -260,7 +260,7 @@ public class SandboxMain : MonoBehaviour - + okButton.OnClickAsAsyncEnumerable().ForEachAsync(_ => @@ -277,6 +277,13 @@ public class SandboxMain : MonoBehaviour this.mcc = null; }); + + okButton.onClick.AddListener(UniTask.UnityAction(async () => await UniTask.Yield())); + } + + async UniTaskVoid CloseAsync(CancellationToken cancellationToken = default) + { + await UniTask.Yield(); } async UniTaskVoid CheckDest()