Class: Zookeeper::Continuation::Registry
- Inherits:
-
Struct
- Object
- Struct
- Zookeeper::Continuation::Registry
- Extended by:
- Forwardable
- Defined in:
- lib/zookeeper/continuation.rb
Overview
for keeping track of which continuations are pending, and which ones have been submitted and are awaiting a repsonse
‘state_check` are high-priority checks that query the connection about its current state, they always run before other continuations
Instance Attribute Summary collapse
-
#in_flight ⇒ Object
Returns the value of attribute in_flight.
-
#pending ⇒ Object
Returns the value of attribute pending.
Instance Method Summary collapse
-
#anything_to_do? ⇒ Boolean
does not lock the mutex, returns true if there are pending jobs.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#next_batch ⇒ Object
returns the pending continuations, resetting the list this method is synchronized.
- #synchronized ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
20 21 22 23 |
# File 'lib/zookeeper/continuation.rb', line 20 def initialize super([], {}) @mutex = Mutex.new end |
Instance Attribute Details
#in_flight ⇒ Object
Returns the value of attribute in_flight
15 16 17 |
# File 'lib/zookeeper/continuation.rb', line 15 def in_flight @in_flight end |
#pending ⇒ Object
Returns the value of attribute pending
15 16 17 |
# File 'lib/zookeeper/continuation.rb', line 15 def pending @pending end |
Instance Method Details
#anything_to_do? ⇒ Boolean
does not lock the mutex, returns true if there are pending jobs
35 36 37 |
# File 'lib/zookeeper/continuation.rb', line 35 def anything_to_do? !pending.empty? end |
#next_batch ⇒ Object
returns the pending continuations, resetting the list this method is synchronized
41 42 43 44 45 46 47 48 |
# File 'lib/zookeeper/continuation.rb', line 41 def next_batch() @mutex.lock begin pending.slice!(0,pending.length) ensure @mutex.unlock rescue nil end end |
#synchronized ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/zookeeper/continuation.rb', line 25 def synchronized @mutex.lock begin yield self ensure @mutex.unlock rescue nil end end |