Class: M2R::MultithreadHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/m2r/multithread_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#threadsObject (readonly)



4
5
6
# File 'lib/m2r/multithread_handler.rb', line 4

def threads
  @threads
end

Instance Method Details

#listenObject



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

#stopObject



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