Class: ProcessPool
- Inherits:
-
Object
- Object
- ProcessPool
- Defined in:
- lib/process/process_pool.rb
Instance Method Summary collapse
- #create_worker(n) ⇒ Object
- #dispose ⇒ Object
- #enqueue(sender, item) ⇒ Object
-
#initialize(server) ⇒ ProcessPool
constructor
A new instance of ProcessPool.
- #kill ⇒ Object
Constructor Details
#initialize(server) ⇒ ProcessPool
12 13 14 15 16 17 |
# File 'lib/process/process_pool.rb', line 12 def initialize(server) @server = server @worker = Array.new @queue = Queue.new end |
Instance Method Details
#create_worker(n) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/process/process_pool.rb', line 21 def create_worker(n) n.times do thread = Thread.new do while true item = @queue.deq(false) @server.handler.each do |handler| handler.recv(@server, item.sender, item.packet) end end end @worker.push thread end end |
#dispose ⇒ Object
18 19 |
# File 'lib/process/process_pool.rb', line 18 def dispose end |
#enqueue(sender, item) ⇒ Object
42 43 44 |
# File 'lib/process/process_pool.rb', line 42 def enqueue(sender, item) @queue.push WorkItem.new(sender, item) end |
#kill ⇒ Object
36 37 38 39 40 |
# File 'lib/process/process_pool.rb', line 36 def kill @worker.each do |worker| worker.kill end end |