Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <summary>
        ///     Resolve the returned promise once the predicate evalutes to true
        /// </summary>
        public IPromise WaitUntil(Func <TimeData, bool> predicate)
        {
            Promise promise = new Promise();

            PredicateWait wait = new PredicateWait {
                timeStarted    = curTime,
                pendingPromise = promise,
                timeData       = new TimeData(),
                predicate      = predicate,
                frameStarted   = curFrame
            };

            waiting.AddLast(wait);

            return(promise);
        }
Exemple #3
0
        /// <summary>
        ///     Update all pending promises. Must be called for the promises to progress and resolve at all.
        /// </summary>
        public void Update(float deltaTime)
        {
            curTime  += deltaTime;
            curFrame += 1;

            LinkedListNode <PredicateWait> node = waiting.First;

            while (node != null)
            {
                PredicateWait wait = node.Value;

                float newElapsedTime = curTime - wait.timeStarted;
                wait.timeData.deltaTime   = newElapsedTime - wait.timeData.elapsedTime;
                wait.timeData.elapsedTime = newElapsedTime;
                int newElapsedUpdates = curFrame - wait.frameStarted;
                wait.timeData.elapsedUpdates = newElapsedUpdates;

                bool result;
                try {
                    result = wait.predicate(wait.timeData);
                }
                catch (Exception ex) {
                    wait.pendingPromise.Reject(ex);

                    node = RemoveNode(node);
                    continue;
                }

                if (result)
                {
                    wait.pendingPromise.Resolve();

                    node = RemoveNode(node);
                }
                else
                {
                    node = node.Next;
                }
            }
        }
        /// <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;
        }