Sha256: e3dbeb47bc48c897ee4ec66bff625c43ca24053421d61f9b2439cc946a30fbd8

Contents?: true

Size: 472 Bytes

Versions: 37

Compression:

Stored size: 472 Bytes

Contents

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

37 entries across 37 versions & 1 rubygems

Version Path
sidekiq-7.3.0 lib/sidekiq/ring_buffer.rb
sidekiq-7.2.4 lib/sidekiq/ring_buffer.rb
sidekiq-7.2.3 lib/sidekiq/ring_buffer.rb
sidekiq-7.2.2 lib/sidekiq/ring_buffer.rb
sidekiq-7.2.1 lib/sidekiq/ring_buffer.rb
sidekiq-7.2.0 lib/sidekiq/ring_buffer.rb
sidekiq-6.5.12 lib/sidekiq/ring_buffer.rb
sidekiq-7.1.6 lib/sidekiq/ring_buffer.rb
sidekiq-6.5.11 lib/sidekiq/ring_buffer.rb
sidekiq-7.1.5 lib/sidekiq/ring_buffer.rb
sidekiq-6.5.10 lib/sidekiq/ring_buffer.rb
sidekiq-7.1.4 lib/sidekiq/ring_buffer.rb
sidekiq-7.1.3 lib/sidekiq/ring_buffer.rb
sidekiq-7.1.2 lib/sidekiq/ring_buffer.rb
sidekiq-7.1.1 lib/sidekiq/ring_buffer.rb
sidekiq-6.5.9 lib/sidekiq/ring_buffer.rb
sidekiq-7.1.0 lib/sidekiq/ring_buffer.rb
sidekiq-7.0.9 lib/sidekiq/ring_buffer.rb
sidekiq-7.0.8 lib/sidekiq/ring_buffer.rb
sidekiq-7.0.7 lib/sidekiq/ring_buffer.rb