Class: MultiHeadedGreekMonster
- Inherits:
-
Object
- Object
- MultiHeadedGreekMonster
- Defined in:
- lib/multi_headed_greek_monster.rb
Defined Under Namespace
Classes: ServiceManager
Instance Method Summary collapse
- #feed(thing) ⇒ Object
- #finish ⇒ Object
-
#initialize(progress = nil, worker_count = 3, on_port = 23121, &block) ⇒ MultiHeadedGreekMonster
constructor
A new instance of MultiHeadedGreekMonster.
- #wait(for_min_q_size = 5, &block) ⇒ Object
Constructor Details
#initialize(progress = nil, worker_count = 3, on_port = 23121, &block) ⇒ MultiHeadedGreekMonster
Returns a new instance of MultiHeadedGreekMonster.
3 4 5 6 7 8 9 10 |
# File 'lib/multi_headed_greek_monster.rb', line 3 def initialize(progress = nil, worker_count = 3, on_port = 23121, &block) @action = block @on_port = on_port @worker_count = worker_count @progress = progress start_service start_workers end |
Instance Method Details
#feed(thing) ⇒ Object
12 13 14 |
# File 'lib/multi_headed_greek_monster.rb', line 12 def feed(thing) @service_manager.give(thing) end |
#finish ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/multi_headed_greek_monster.rb', line 25 def finish @service_manager.done! while(!@service_manager.done?) sleep(1) end results = @service_manager.results @worker_pids.each do |pid| Process.wait(pid) end Process.kill("KILL", @server_pid) results end |
#wait(for_min_q_size = 5, &block) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/multi_headed_greek_monster.rb', line 16 def wait(for_min_q_size = 5, &block) while(@service_manager.q_size > for_min_q_size) sleep(1) if block_given? yield end end end |