27 private readonly
object _sync =
new object();
29 private long _nextRefillTimeTicks;
31 private readonly
long _refillAmount;
32 private readonly
long _refillIntervalTicks;
46 _timeProvider = timeProvider;
47 _refillAmount = refillAmount;
48 _refillIntervalTicks = refillInterval.Ticks;
49 _nextRefillTimeTicks = _timeProvider.
GetUtcNow().Ticks + _refillIntervalTicks;
61 var currentTimeTicks = _timeProvider.GetUtcNow().Ticks;
62 if (currentTimeTicks < _nextRefillTimeTicks)
68 var deltaTimeTicks = currentTimeTicks - _nextRefillTimeTicks;
69 var intervalsElapsed = 1 + Math.Max(deltaTimeTicks / _refillIntervalTicks, 0);
72 _nextRefillTimeTicks += _refillIntervalTicks * intervalsElapsed;
75 return _refillAmount * intervalsElapsed;