File: max_queue.rb

package info (click to toggle)
ruby-influxdb 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 424 kB
  • sloc: ruby: 3,530; sh: 61; makefile: 7
file content (17 lines) | stat: -rw-r--r-- 303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module InfluxDB
  # Queue with max length limit
  class MaxQueue < Queue
    attr_reader :max

    def initialize(max = 10_000)
      raise ArgumentError, "queue size must be positive" if max <= 0

      @max = max
      super()
    end

    def push(obj)
      super if length < @max
    end
  end
end