Module: Fleck::Core::Consumer::Base::ClassMethods
- Defined in:
- lib/fleck/core/consumer/base.rb
Overview
Defines class methods to import when ‘Autostart` module is imported.
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#consumers ⇒ Object
Returns the value of attribute consumers.
-
#initialize_block ⇒ Object
Returns the value of attribute initialize_block.
-
#lock ⇒ Object
Returns the value of attribute lock.
Instance Method Summary collapse
- #inherited(subclass) ⇒ Object
- #initialize(&block) ⇒ Object
- #on_terminate(consumer) ⇒ Object
- #start(block: false) ⇒ Object
- #terminate ⇒ Object
- #wait_termination ⇒ Object
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
15 16 17 |
# File 'lib/fleck/core/consumer/base.rb', line 15 def condition @condition end |
#consumers ⇒ Object
Returns the value of attribute consumers.
15 16 17 |
# File 'lib/fleck/core/consumer/base.rb', line 15 def consumers @consumers end |
#initialize_block ⇒ Object
Returns the value of attribute initialize_block.
15 16 17 |
# File 'lib/fleck/core/consumer/base.rb', line 15 def initialize_block @initialize_block end |
#lock ⇒ Object
Returns the value of attribute lock.
15 16 17 |
# File 'lib/fleck/core/consumer/base.rb', line 15 def lock @lock end |
Instance Method Details
#inherited(subclass) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/fleck/core/consumer/base.rb', line 17 def inherited(subclass) super return if subclass == Fleck::Consumer init_consumer(subclass) autostart(subclass) Fleck.register_consumer(subclass) end |
#initialize(&block) ⇒ Object
26 27 28 |
# File 'lib/fleck/core/consumer/base.rb', line 26 def initialize(&block) self.initialize_block = block end |
#on_terminate(consumer) ⇒ Object
39 40 41 42 |
# File 'lib/fleck/core/consumer/base.rb', line 39 def on_terminate(consumer) consumers.delete consumer terminate if consumers.empty? end |
#start(block: false) ⇒ Object
30 31 32 33 |
# File 'lib/fleck/core/consumer/base.rb', line 30 def start(block: false) consumers.each(&:start) wait_termination if block end |
#terminate ⇒ Object
44 45 46 47 |
# File 'lib/fleck/core/consumer/base.rb', line 44 def terminate consumers.each(&:terminate) lock.synchronize { condition.signal } end |
#wait_termination ⇒ Object
35 36 37 |
# File 'lib/fleck/core/consumer/base.rb', line 35 def wait_termination lock.synchronize { condition.wait(lock) } end |