Await a motion or cancel a wait
Choose whether closing a screen should stop the tween or just end the task waiting for it. The wait token and the motion's own cancellation control different outcomes.
Starting a wait on a playing motion
| Wait | Normal completion | Motion canceled while waiting |
|---|---|---|
await handle |
Resumes | Resumes |
await handle.ToValueTask() |
Resumes | OperationCanceledException |
await handle.ToAwaitable() |
Resumes | OperationCanceledException |
yield return handle.ToYieldInstruction() |
Resumes when the handle becomes inactive | Resumes when inactive |
A preserved tween can remain active after reaching its endpoint. The coroutine polls IsActive, which matters if you preserve a motion. Asking an already inactive handle for a ValueTask or Awaitable produces an already completed wait. MotionHandle · Awaiting extensions
Canceling the wait token
Canceling the token cancels a wait started on a playing motion. CancelBehavior selects the effect on the motion itself.
| CancelBehavior | Effect on the tween |
|---|---|
| None | Continue playing |
| Cancel | Try to cancel at the current value |
| Complete | Try to complete at the endpoint. Infinite motions cannot complete |
This method leaves the tween playing if the caller closes the screen. It returns true on normal completion and false when the caller cancels the token. Cancellation of the motion from elsewhere propagates to the caller.
using System;
using System.Threading;
using System.Threading.Tasks;
using MeatMotion;
public static class MotionWaitExample
{
public static async ValueTask<bool> WaitWhileOpen(
MotionHandle motion, CancellationToken screenClosed)
{
try
{
await motion.ToValueTask(CancelBehavior.None, screenClosed);
return true;
}
catch (OperationCanceledException) when (screenClosed.IsCancellationRequested)
{
return false;
}
}
}
To resume normally when the motion itself is canceled, use the overload with cancelAwaitOnMotionCanceled set to false. That flag is independent of cancellation through the wait token. ToValueTask overloads · CancelBehavior options
MeatMotion