Sha256: c896ce29bb9a41409abd97588a5b54fd03a00d10c16985025b4a0128f345bfd0

Contents?: true

Size: 503 Bytes

Versions: 7

Compression:

Stored size: 503 Bytes

Contents

# frozen_string_literal: true

require "forwardable"

module Sidekiq
  class RingBuffer
    include Enumerable
    extend Forwardable
    def_delegators :@buf, :[], :each, :size

    def initialize(size, default = 0)
      @size = size
      @buf = Array.new(size, default)
      @index = 0
    end

    def <<(element)
      @buf[@index % @size] = element
      @index += 1
      element
    end

    def buffer
      @buf
    end

    def reset(default = 0)
      @buf.fill(default)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sidekiq-7.3.7 lib/sidekiq/ring_buffer.rb
sidekiq-7.3.6 lib/sidekiq/ring_buffer.rb
sidekiq-7.3.5 lib/sidekiq/ring_buffer.rb
sidekiq-7.3.4 lib/sidekiq/ring_buffer.rb
sidekiq-7.3.3 lib/sidekiq/ring_buffer.rb
sidekiq-7.3.2 lib/sidekiq/ring_buffer.rb
sidekiq-7.3.1 lib/sidekiq/ring_buffer.rb