Пример #1
0
 private void OnChallengeIssuedSuccess(AcceptChallengeResponse response)
 {
     if (ThrottleHandler.IsRequestThrottled(response.Errors.JSON))
     {
         var request = lastAcceptChallengeRequest;
         request.Send(OnChallengeIssuedSuccess);
     }
 }
 public void OnMatchmakingError(MatchmakingResponse response)
 {
     //UnblockInput();
     Debug.Log("Matchmaking Error");
     if (ThrottleHandler.IsRequestThrottled(response.Errors.JSON))
     {
         Invoke("AttemptSendMatchRequest", ThrottleHandler.GetRandomTime());
     }
 }
Пример #3
0
 public void OnMatchmakingError(MatchmakingResponse response)
 {
     //UnblockInput();
     Debug.Log("Matchmaking Error");
     if (ThrottleHandler.IsRequestThrottled(response.Errors.JSON))
     {
         var request = lastMatchmakingRequest;
         request.Send(OnMatchmakingSuccess, OnMatchmakingError);
     }
 }
 public void OnFindPendingMatchesRequestError(FindPendingMatchesResponse response)
 {
     Debug.Log("Find Matches Error: " + response.Errors.JSON);
     UnblockRefreshInput();
     refreshingLock = false;
     if (ThrottleHandler.IsRequestThrottled(response.Errors.JSON))
     {
         Invoke("AttemptSendFindRequest", ThrottleHandler.GetRandomTime());
     }
 }
Пример #5
0
        private Func <T, Task <TResult> > ThrottleImpl <T, TResult>(Func <T, TResult> function, int milliseconds, bool leading = true)
        {
            var fn = function;
            ThrottleHandler <T, TResult> throttler = null;
            var      hashset     = new HashSet <object>();
            object   fnlock      = null;
            var      sharedLock  = new object();
            DateTime firstCalled = DateTime.MinValue;

            return(async targ =>
            {
                object localHandle = new object();
                object localLock;
                HashSet <object> localHashset;
                ThrottleHandler <T, TResult> localThrottler;
                TResult returning;

                lock (sharedLock)
                {
                    if ((DateTime.Now - firstCalled).TotalMilliseconds >= milliseconds)
                    {
                        fnlock = null;
                        throttler = null;
                        hashset = null;
                        firstCalled = DateTime.Now;
                    }

                    bool isFirst = false;
                    if (fnlock == null)
                    {
                        fnlock = new object();
                        firstCalled = DateTime.Now;
                        isFirst = true;
                    }


                    localLock = fnlock;

                    if (throttler == null)
                    {
                        throttler = new ThrottleHandler <T, TResult>(_math, function, milliseconds, false);
                    }

                    localThrottler = throttler;

                    if (hashset == null)
                    {
                        hashset = new HashSet <object>();
                    }

                    localHashset = hashset;


                    if (isFirst && leading)
                    {
                        return fn(targ);
                    }
                }


                lock (localLock)
                    localHashset.Add(localHandle);

                returning = await throttler.Result(targ);

                lock (localLock)
                    localHashset.Remove(localHandle);

                lock (sharedLock)
                    if (localHashset == hashset && localHashset != null && localHashset.Count == 0)
                    {
                        if (localLock == fnlock)
                        {
                            fnlock = null;
                        }

                        if (localThrottler == throttler)
                        {
                            throttler = null;
                        }

                        if (localHashset == hashset)
                        {
                            hashset = null;
                        }
                    }


                return returning;
            });
        }