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.
-
#state_check ⇒ Object
Returns the value of attribute state_check.
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.
- #synchronize ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
22 23 24 25 |
# File 'lib/zookeeper/continuation.rb', line 22 def initialize super([], [], {}) @mutex = Mutex.new end |
Instance Attribute Details
#in_flight ⇒ Object
Returns the value of attribute in_flight
17 18 19 |
# File 'lib/zookeeper/continuation.rb', line 17 def in_flight @in_flight end |
#pending ⇒ Object
Returns the value of attribute pending
17 18 19 |
# File 'lib/zookeeper/continuation.rb', line 17 def pending @pending end |
#state_check ⇒ Object
Returns the value of attribute state_check
17 18 19 |
# File 'lib/zookeeper/continuation.rb', line 17 def state_check @state_check end |
Instance Method Details
#anything_to_do? ⇒ Boolean
does not lock the mutex, returns true if there are pending jobs
37 38 39 |
# File 'lib/zookeeper/continuation.rb', line 37 def anything_to_do? (pending.length + state_check.length) > 0 end |
#next_batch ⇒ Object
returns the pending continuations, resetting the list this method is synchronized
43 44 45 46 47 48 49 50 |
# File 'lib/zookeeper/continuation.rb', line 43 def next_batch() @mutex.lock begin state_check.slice!(0, state_check.length) + pending.slice!(0,pending.length) ensure @mutex.unlock rescue nil end end |
#synchronize ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/zookeeper/continuation.rb', line 27 def synchronize @mutex.lock begin yield self ensure @mutex.unlock rescue nil end end |