예제 #1
0
        private async Task AddItem(int distance, TimerItem <T> item)
        {
            await sectorHandling.WaitAsync().ConfigureAwait(false);

            this[(currentTick + distance) % wheelSize].Items.Add(item);
            sectorHandling.Release();
        }
예제 #2
0
        public async Task AddItem(DateTime startTime, TimerItem <T> item)
        {
            TimeSpan initialInterval = startTime.Subtract(DateTime.UtcNow);

            await this.AddInitialTime(initialInterval, item);

            this.timerItems.Add(item.TimerItemId, item);
        }
예제 #3
0
 private void RemoveItem(TimerItem <T> item)
 {
     if (null != carryOverWheel)
     {
         carryOverWheel.RemoveItem(item);
     }
     foreach (var sector in this.sectors)
     {
         sector?.Items?.Remove(item);
     }
 }
예제 #4
0
        public async Task <bool> RemoveTimerItem(Guid timerItemId)
        {
            if (timerItems.ContainsKey(timerItemId))
            {
                TimerItem <T> item = timerItems[timerItemId];
                timerItems.Remove(timerItemId);
                await sectorHandling.WaitAsync().ConfigureAwait(false);

                RemoveItem(item);
                sectorHandling.Release();
                return(true);
            }
            return(false);
        }
예제 #5
0
 protected async Task AddInitialTime(TimeSpan startInterval, TimerItem <T> item)
 {
     //get largest wheel required
     if (this.wheelSpan < startInterval.TotalMilliseconds)
     {
         if (null == this.carryOverWheel)
         {
             this.carryOverWheel = new TimerWheel <T>(this.wheelSize, baseInterval, this.rank + 1);
         }
         item.ExecutionTick += this.currentTick * this.sectorSpan;
         await this.carryOverWheel.AddInitialTime(startInterval, item).ConfigureAwait(false);
     }
     else
     {
         int nextTickTime = (int)(startInterval.TotalMilliseconds + item.ExecutionTick);
         item.ExecutionTick = nextTickTime % this.sectorSpan;
         //timerWheels.ForEach(x => { System.Diagnostics.Debug.Write($"{x.Magnitude}:{x.CurrentTick} "); });
         await this.AddItem((int)(nextTickTime / this.sectorSpan), item);
     }
 }
예제 #6
0
 public async Task Add(DateTime startTime, TimerItem <T> item)
 {
     await baseTimer.AddItem(startTime, item);
 }
예제 #7
0
 public async Task Add(TimerItem <T> item)
 {
     await baseTimer.AddItem(item);
 }
예제 #8
0
        public async Task AddItem(TimeSpan initialInterval, TimerItem <T> item)
        {
            await this.AddInitialTime(initialInterval, item);

            this.timerItems.Add(item.TimerItemId, item);
        }
예제 #9
0
        public async Task AddItem(TimerItem <T> item)
        {
            await this.AddItem(1, item);

            this.timerItems.Add(item.TimerItemId, item);
        }