AnnulusGames/LitMotion

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

AnnulusGames opened this issue · 3 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.