Class: PersistentQueue
- Inherits:
-
SmartQueue
- Object
- SmartQueue
- PersistentQueue
- Defined in:
- lib/ruby-threading-toolkit/persistent_queue.rb
Instance Attribute Summary collapse
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
Methods inherited from SmartQueue
#concat, #empty?, #flush, #initialize, #priority_concat, #priority_enqueue, #priority_push, #push, #regular_enqueue, #regular_limit=, #release_blocked, #select, #shift
Constructor Details
This class inherits a constructor from SmartQueue
Instance Attribute Details
#storage ⇒ Object
Returns the value of attribute storage.
18 19 20 |
# File 'lib/ruby-threading-toolkit/persistent_queue.rb', line 18 def storage @storage end |
Instance Method Details
#restore ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby-threading-toolkit/persistent_queue.rb', line 20 def restore @mutex.synchronize do if @storage.exist? data = Marshal.restore(@storage.read) @storage.delete @regular = data[:regular] @priority = data[:priority] end end end |
#store_and_close ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-threading-toolkit/persistent_queue.rb', line 32 def store_and_close @mutex.synchronize do @storage.write Marshal.dump({:regular => @regular, :priority => @priority}) # This will simply raise exception on trying to push/pop from/to queue @regular = nil @priority = nil end end |