/// <summary> /// Task style-- will throw if cancelled. This checks cT.IsCancelled before returning, /// so you do not need to check it after awaiting this. /// </summary> /// <returns></returns> public static async Task WaitFor(BehaviorEntity Exec, ICancellee cT, float time, bool zeroToInfinity) { cT.ThrowIfCancelled(); if (zeroToInfinity && time < float.Epsilon) { time = float.MaxValue; } if (time < float.Epsilon) { return; } Exec.RunRIEnumerator(WaitFor(time, cT, GetAwaiter(out Task t))); await t; //I do want this throw here, which is why I don't 'return t' cT.ThrowIfCancelled(); }
/// <summary> /// Outer waiter-- Will cb if cancelled /// </summary> public static void WaitThenCBEvenIfCancelled(CoroutineRegularUpdater Exec, ICancellee cT, float time, bool zeroToInfinity, Action cb) { cT.ThrowIfCancelled(); if (zeroToInfinity && time < float.Epsilon) { time = float.MaxValue; } Exec.RunRIEnumerator(WaitFor(time, cT, cb)); }
/// <summary> /// Outer waiter-- Will not cb if cancelled /// </summary> public static void WaitThenCB(CoroutineRegularUpdater Exec, ICancellee cT, float time, Func <bool> condition, Action cb) { cT.ThrowIfCancelled(); Exec.RunRIEnumerator(WaitForBoth(time, condition, cT, () => { if (!cT.Cancelled) { cb(); } })); }
/// <summary> /// Task style. Will return as soon as the time is up or cancellation is triggered. /// You must check cT.IsCancelled after awaiting this. /// </summary> /// <returns></returns> public static Task WaitForUnchecked(CoroutineRegularUpdater Exec, ICancellee cT, float time, bool zeroToInfinity) { cT.ThrowIfCancelled(); if (zeroToInfinity && time < float.Epsilon) { time = float.MaxValue; } if (time < float.Epsilon) { return(Task.CompletedTask); } Exec.RunRIEnumerator(WaitFor(time, cT, GetAwaiter(out Task t))); return(t); }
/// <summary> /// Outer waiter-- Will not cancel if cancelled /// </summary> public static void WaitThenCancel(CoroutineRegularUpdater Exec, ICancellee cT, float time, bool zeroToInfinity, Cancellable toCancel) { cT.ThrowIfCancelled(); if (zeroToInfinity && time < float.Epsilon) { time = float.MaxValue; } Exec.RunRIEnumerator(WaitFor(time, cT, () => { if (!cT.Cancelled) { toCancel.Cancel(); } })); }
/// <summary> /// Task style. Will return as soon as the condition is satisfied or cancellation is triggered. /// You must check cT.IsCancelled after awaiting this. /// </summary> /// <returns></returns> public static Task WaitForUnchecked(CoroutineRegularUpdater Exec, ICancellee cT, Func <bool> condition) { cT.ThrowIfCancelled(); Exec.RunRIEnumerator(WaitFor(condition, cT, GetAwaiter(out Task t))); return(t); }