AnnulusGames / LitMotion

Lightning-fast and Zero Allocation Tween Library for Unity.

Home Page:https://annulusgames.github.io/LitMotion/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] await MotionHandle does not complete when calling handle.Cancel()

AnnulusGames opened this issue · comments

Await does not complete when MotionHandle is canceled while waiting with await.

[UnityTest]
public IEnumerator Test_CancelWhileAwait() => UniTask.ToCoroutine(async () =>
{
    var handle = LMotion.Create(0f, 10f, 1f).BindToUnityLogger();
    DelayedCall(0.2f, () => handle.Cancel()).Forget();
    await handle; // never complete
});

async UniTaskVoid DelayedCall(float delay, Action action)
{
    await UniTask.WaitForSeconds(delay);
    action.Invoke();
}

I think creating bool TreatCancelAsComplete or enum CancelBehaviour and allowing access and modification from the handle would solve the problem.

Fixed in #15

This doesn't work with WithCancelOnError.