Class: RefillingQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/refilling_queue.rb,
lib/refilling_queue/version.rb

Defined Under Namespace

Classes: Locked

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :lock_timeout => 60,
  :refresh_every => nil,
  :paginate => false
}
VERSION =
'0.1.0'

Instance Method Summary collapse

Constructor Details

#initialize(client, name, options = {}, &block) ⇒ RefillingQueue

Returns a new instance of RefillingQueue.



13
14
15
16
17
18
# File 'lib/refilling_queue.rb', line 13

def initialize(client, name, options={}, &block)
  @client, @name, @block = client, name, block
  @page_name = name + "/page"
  @options = DEFAULT_OPTIONS.merge(options)
  raise "Invalid keys" if (options.keys - DEFAULT_OPTIONS.keys).any?
end

Instance Method Details

#clearObject



27
28
29
30
31
32
# File 'lib/refilling_queue.rb', line 27

def clear
  lock do
    mark_as_empty
    _refill
  end
end

#popObject



20
21
22
23
24
25
# File 'lib/refilling_queue.rb', line 20

def pop
  item = _pop
  return item unless item.nil?
  refill
  _pop
end