Class: Redrate::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/redrate/queue.rb

Constant Summary collapse

EPOCH =
0

Instance Method Summary collapse

Constructor Details

#initialize(size, interval: 60, key: 'queue') ⇒ Queue

Returns a new instance of Queue.



9
10
11
12
# File 'lib/redrate/queue.rb', line 9

def initialize(size, interval: 60, key: 'queue')
  @ring = Ring.new(size, key, EPOCH)
  @interval = interval
end

Instance Method Details

#shiftObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/redrate/queue.rb', line 14

def shift
  time = nil

  @ring.lock do
    sleep_until(@ring.current + @interval)
    @ring.rotate!
  end

  time
end