rename UniTask.VoidAction -> UniTask.Action, UniTask.VoidUnityAction -> UniTask.UnityAction, there return type Func<UniTask> -> Func<UniTaskVoid>

master
neuecc 2020-05-22 21:42:23 +09:00
parent 78f56b9b33
commit ec0123eec7
2 changed files with 56 additions and 16 deletions

View File

@ -105,34 +105,67 @@ namespace Cysharp.Threading.Tasks
/// helper of create add UniTaskVoid to delegate. /// helper of create add UniTaskVoid to delegate.
/// For example: FooEvent += () => UniTask.Void(async () => { /* */ }) /// For example: FooEvent += () => UniTask.Void(async () => { /* */ })
/// </summary> /// </summary>
public static void Void(Func<UniTask> asyncAction) public static void Void(Func<UniTaskVoid> asyncAction)
{ {
asyncAction().Forget(); asyncAction().Forget();
} }
public static Action VoidAction(Func<UniTask> asyncAction) /// <summary>
/// helper of create add UniTaskVoid to delegate.
/// </summary>
public static void Void(Func<CancellationToken, UniTaskVoid> asyncAction, CancellationToken cancellationToken)
{ {
return () => Void(asyncAction); asyncAction(cancellationToken).Forget();
} }
#if UNITY_2018_3_OR_NEWER
public static UnityEngine.Events.UnityAction VoidUnityAction(Func<UniTask> asyncAction)
{
return () => Void(asyncAction);
}
#endif
/// <summary> /// <summary>
/// helper of create add UniTaskVoid to delegate. /// helper of create add UniTaskVoid to delegate.
/// For example: FooEvent += (sender, e) => UniTask.Void(async arg => { /* */ }, (sender, e)) /// For example: FooEvent += (sender, e) => UniTask.Void(async arg => { /* */ }, (sender, e))
/// </summary> /// </summary>
public static void Void<T>(Func<T, UniTask> asyncAction, T state) public static void Void<T>(Func<T, UniTaskVoid> asyncAction, T state)
{ {
asyncAction(state).Forget(); asyncAction(state).Forget();
} }
/// <summary>
/// helper of create add UniTaskVoid to delegate.
/// For example: FooAction = UniTask.Action(async () => { /* */ })
/// </summary>
public static Action Action(Func<UniTaskVoid> asyncAction)
{
return () => asyncAction().Forget();
}
/// <summary>
/// helper of create add UniTaskVoid to delegate.
/// </summary>
public static Action Action(Func<CancellationToken, UniTaskVoid> asyncAction, CancellationToken cancellationToken)
{
return () => asyncAction(cancellationToken).Forget();
}
#if UNITY_2018_3_OR_NEWER
/// <summary>
/// Create async void(UniTaskVoid) UnityAction.
/// For exampe: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } ))
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<UniTaskVoid> asyncAction)
{
return () => asyncAction().Forget();
}
/// <summary>
/// Create async void(UniTaskVoid) UnityAction.
/// For exampe: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy()))
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<CancellationToken, UniTaskVoid> asyncAction, CancellationToken cancellationToken)
{
return () => asyncAction(cancellationToken).Forget();
}
#endif
/// <summary> /// <summary>
/// Defer the task creation just before call await. /// Defer the task creation just before call await.
/// </summary> /// </summary>

View File

@ -142,7 +142,7 @@ public class SandboxMain : MonoBehaviour
{ {
// State<int> Hp { get; } // State<int> Hp { get; }
public Model() public Model()
@ -173,7 +173,7 @@ public class SandboxMain : MonoBehaviour
void Start2() void Start2()
{ {
} }
@ -260,7 +260,7 @@ public class SandboxMain : MonoBehaviour
okButton.OnClickAsAsyncEnumerable().ForEachAsync(_ => okButton.OnClickAsAsyncEnumerable().ForEachAsync(_ =>
@ -277,6 +277,13 @@ public class SandboxMain : MonoBehaviour
this.mcc = null; this.mcc = null;
}); });
okButton.onClick.AddListener(UniTask.UnityAction(async () => await UniTask.Yield()));
}
async UniTaskVoid CloseAsync(CancellationToken cancellationToken = default)
{
await UniTask.Yield();
} }
async UniTaskVoid CheckDest() async UniTaskVoid CheckDest()