lib/simple_throttle.rb in simple_throttle-1.0.6 vs lib/simple_throttle.rb in simple_throttle-1.0.7

- old
+ new

@@ -155,10 +155,12 @@ # Peek at the current number for throttled calls being tracked. # # @return [Integer] def peek - current_size(false) + timestamps = redis_client.lrange(redis_key, 0, -1).collect(&:to_i) + min_timestamp = ((Time.now.to_f - ttl) * 1000).ceil + timestamps.count { |t| t > min_timestamp } end # Returns when the next resource call should be allowed. Note that this doesn't guarantee that # calling allow! will return true if the wait time is zero since other processes or threads can # claim the resource.