mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
67daa7a408
* Prepare for upcoming Sidekiq::Config redesign Adjust the server internals to use a config object rather than refering directly to the Sidekiq module.
29 lines
472 B
Ruby
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
|