public void Update(float deltaTime) { curTime += deltaTime; int num = 0; while (num < waiting.Count) { PredicateWait predicateWait = waiting[num]; float num2 = curTime - predicateWait.timeStarted; predicateWait.timeData.deltaTime = num2 - predicateWait.timeData.elapsedTime; predicateWait.timeData.elapsedTime = num2; bool flag; try { flag = predicateWait.predicate(predicateWait.timeData); } catch (Exception ex) { predicateWait.pendingPromise.Reject(ex); waiting.RemoveAt(num); continue; } if (flag) { predicateWait.pendingPromise.Resolve(); waiting.RemoveAt(num); } else { num++; } } }
public IPromise WaitUntil(Func <TimeData, bool> predicate) { Promise promise = new Promise(); PredicateWait predicateWait = new PredicateWait(); predicateWait.timeStarted = curTime; predicateWait.pendingPromise = promise; predicateWait.timeData = default(TimeData); predicateWait.predicate = predicate; PredicateWait item = predicateWait; waiting.Add(item); return(promise); }
/// <summary> /// Resolve the returned promise once the predicate evalutes to true /// </summary> public IPromise WaitUntil(Func <TimeData, bool> predicate) { var promise = new Promise(); var wait = new PredicateWait() { timeStarted = curTime, pendingPromise = promise, timeData = new TimeData(), predicate = predicate }; waiting.Add(wait); return(promise); }