Example #1
0
        /// <summary>
        /// Debounceds the call
        /// </summary>
        protected void DebouncedCall()
        {
            float time       = now();
            bool  isInvoking = shouldInvoke(time);

            debounced    = true;
            lastCallTime = time;

            if (isInvoking)
            {
                if (deferred == null)
                {
                    leadingEdge(time);
                    return;
                }
                if (maxWait.HasValue)
                {
                    // Handle invocations in a tight loop
                    deferred = timing.After(maxWait.Value, timerExpired);
                    invokeFunc(time);
                    return;
                }
            }
            if (deferred == null)
            {
                deferred = timing.After(wait, timerExpired);
            }
        }
 IEnumerator loop(IDeferred d)
 {
     for (int i = 0; i < 10; ++i) {
         _loopCount++;
         yield return null;
     }
     d.Resolve();
 }
Example #3
0
 /// <inheritdoc />
 public void Abort()
 {
     if (deferred != null)
     {
         deferred.Abort();
     }
     lastInvokeTime = 0;
     lastCallTime   = null;
     deferred       = null;
     DoResetArgs();
 }
Example #4
0
        private void timerExpired()
        {
            float time = now();

            if (shouldInvoke(time))
            {
                trailingEdge(time);
                return;
            }
            // Restart the timer
            deferred = timing.After(remainingWait(time), timerExpired);
        }
Example #5
0
 private void leadingEdge(float time)
 {
     // Reset any `maxWait` timer
     lastInvokeTime = time;
     // Start the timer for the trailing edge
     deferred = timing.After(wait, timerExpired);
     // Invoke the leading edge
     if (leading)
     {
         invokeFunc(wait);
     }
 }
Example #6
0
 private void trailingEdge(float time)
 {
     deferred = null;
     // Only invoke if we have `lastArgs` which means `func` has been
     // debounced at least once.
     if (trailing && debounced)
     {
         invokeFunc(time);
         return;
     }
     DoResetArgs();
     debounced = false;
 }
Example #7
0
        /// <inheritdoc />
        public IDeferred Every(float seconds, Action callback)
        {
            IDeferred deferred = null;

            deferred = new UnityDeferred(seconds, () => {
                callback();
                if (deferred != null && !deferred.Aborted)
                {
                    deferred.Start();
                }
            });
            deferred.Start();
            return(deferred);
        }
Example #8
0
        public IEnumerator WrapWWW(IDeferred d)
        {
            float progress = 0;

            WWW www = new WWW(URL);
            while (!www.isDone) {
                if (progress < www.progress) {
                    progress = www.progress;
                    d.Notify(progress);
                }
                yield return new WaitForSeconds(0.1f);
            }

            if (String.IsNullOrEmpty(www.error)) {
                d.Resolve(www.text);
            } else {
                d.Reject(www.error);
            }
        }
Example #9
0
 public DeferredPromise(IDeferred <D, F, P> deferred)
 {
     this.deferred = deferred;
     this.promise  = deferred.Promise();
 }