1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/ring_buffer.rb
Mike Perham 67daa7a408
Prepare for upcoming Sidekiq::Config redesign (#5340)
* Prepare for upcoming Sidekiq::Config redesign

Adjust the server internals to use a config object rather than refering directly to the Sidekiq module.
2022-05-31 13:37:31 -07:00

29 lines
472 B
Ruby

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