BoxKite.Twitter.TwitterConnection.GetDirectMessages_Received_Backfill C# (CSharp) Метод

GetDirectMessages_Received_Backfill() приватный Метод

private GetDirectMessages_Received_Backfill ( ) : Task
Результат Task
        private async Task<long> GetDirectMessages_Received_Backfill()
        {
            long smallestid = 0;
            long largestid = 0;
            int backfillQuota = 50;
            int backofftimer = 30;

            do
            {
                var dmrecd = await UserSession.GetDirectMessages(count: _pagingSize, maxId: smallestid);
                if (dmrecd.OK)
                {
                    smallestid = long.MaxValue;
                    // if the Count of items returned is less than the backfill quota, we have run out of messages.
                    // this will decrement the backfill quota to zero, falling out of the loop
                    if (dmrecd.Count < backfillQuota) backfillQuota = dmrecd.Count;
                    foreach (var dm in dmrecd)
                    {
                        _directmessages.OnNext(dm);
                        if (dm.Id < smallestid) smallestid = dm.Id;
                        if (dm.Id > largestid) largestid = dm.Id;
                        backfillQuota--;
                    }
                    await Task.Delay(_multiFetchBackoffTimer);
                }
                else
                {
                    // The Backoff will trigger 7 times before just giving up
                    // once at 30s, 60s, 1m, 2m, 4m, 8m and then 16m
                    // note that the last call into this will be 1m above the 15 "rate limit reset" window 
                    await Task.Delay(TimeSpan.FromSeconds(backofftimer));
                    if (backofftimer > _maxbackoff)
                        break;
                    backofftimer = backofftimer * 2;
                }
            } while (backfillQuota > 0);
            return largestid;
        }