fix action

master
neuecc 2020-06-04 14:58:11 +09:00
parent 83596b3d1f
commit b2f82df4d3
2 changed files with 9 additions and 193 deletions

View File

@ -133,7 +133,7 @@ namespace Cysharp.Threading.Tasks
/// </summary>
public static Action Action(Func<UniTaskVoid> asyncAction)
{
return AsyncAction.Create(asyncAction);
return () => asyncAction().Forget();
}
/// <summary>
@ -141,7 +141,7 @@ namespace Cysharp.Threading.Tasks
/// </summary>
public static Action Action(Func<CancellationToken, UniTaskVoid> 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
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<UniTaskVoid> asyncAction)
{
return AsyncUnityAction.Create(asyncAction);
return () => asyncAction().Forget();
}
/// <summary>
@ -161,7 +161,7 @@ namespace Cysharp.Threading.Tasks
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<CancellationToken, UniTaskVoid> 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<AsyncAction>
{
static TaskPool<AsyncAction> pool;
public AsyncAction NextNode { get; set; }
static AsyncAction()
{
TaskPool.RegisterSizeGetter(typeof(AsyncAction), () => pool.Size);
}
readonly Action runDelegate;
Func<UniTaskVoid> voidAction;
AsyncAction()
{
runDelegate = Run;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Action Create(Func<UniTaskVoid> 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<AsyncActionWithCancellation>
{
static TaskPool<AsyncActionWithCancellation> pool;
public AsyncActionWithCancellation NextNode { get; set; }
static AsyncActionWithCancellation()
{
TaskPool.RegisterSizeGetter(typeof(AsyncActionWithCancellation), () => pool.Size);
}
readonly Action runDelegate;
CancellationToken cancellationToken;
Func<CancellationToken, UniTaskVoid> voidAction;
AsyncActionWithCancellation()
{
runDelegate = Run;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Action Create(Func<CancellationToken, UniTaskVoid> 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<AsyncUnityAction>
{
static TaskPool<AsyncUnityAction> pool;
public AsyncUnityAction NextNode { get; set; }
static AsyncUnityAction()
{
TaskPool.RegisterSizeGetter(typeof(AsyncUnityAction), () => pool.Size);
}
readonly UnityEngine.Events.UnityAction runDelegate;
Func<UniTaskVoid> voidAction;
AsyncUnityAction()
{
runDelegate = Run;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static UnityEngine.Events.UnityAction Create(Func<UniTaskVoid> 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<AsyncUnityActionWithCancellation>
{
static TaskPool<AsyncUnityActionWithCancellation> pool;
public AsyncUnityActionWithCancellation NextNode { get; set; }
static AsyncUnityActionWithCancellation()
{
TaskPool.RegisterSizeGetter(typeof(AsyncUnityActionWithCancellation), () => pool.Size);
}
readonly UnityEngine.Events.UnityAction runDelegate;
CancellationToken cancellationToken;
Func<CancellationToken, UniTaskVoid> voidAction;
AsyncUnityActionWithCancellation()
{
runDelegate = Run;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static UnityEngine.Events.UnityAction Create(Func<CancellationToken, UniTaskVoid> 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

View File

@ -383,7 +383,11 @@ public class SandboxMain : MonoBehaviour
//{
okButton.onClick.AddListener(UniTask.UnityAction(async () =>
{
await UniTask.Yield();
Debug.Log("Yeha");
}));
//}).Forget();