Class: M2R::MultithreadHandler
- Inherits:
-
Object
- Object
- M2R::MultithreadHandler
- Defined in:
- lib/m2r/multithread_handler.rb
Instance Attribute Summary collapse
- #threads ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(singlethread_handler_factory) ⇒ MultithreadHandler
constructor
A new instance of MultithreadHandler.
- #listen ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(singlethread_handler_factory) ⇒ MultithreadHandler
Returns a new instance of MultithreadHandler.
6 7 8 |
# File 'lib/m2r/multithread_handler.rb', line 6 def initialize(singlethread_handler_factory) @singlethread_handler_factory = singlethread_handler_factory end |
Instance Attribute Details
#threads ⇒ Object (readonly)
4 5 6 |
# File 'lib/m2r/multithread_handler.rb', line 4 def threads @threads end |
Instance Method Details
#listen ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/m2r/multithread_handler.rb', line 10 def listen @threads = 8.times.map do Thread.new do handler = @singlethread_handler_factory.new Thread.current[:m2r_handler] = handler handler.listen end end end |
#stop ⇒ Object
20 21 22 23 24 |
# File 'lib/m2r/multithread_handler.rb', line 20 def stop @threads.each do |t| t[:m2r_handler].stop end end |