Class: Async::Container::Threaded
- Inherits:
-
Object
- Object
- Async::Container::Threaded
- Defined in:
- lib/async/container/threaded.rb
Overview
Manages a reactor within one or more threads.
Instance Method Summary collapse
-
#initialize(concurrency: 1, &block) ⇒ Threaded
constructor
A new instance of Threaded.
- #stop ⇒ Object
Constructor Details
#initialize(concurrency: 1, &block) ⇒ Threaded
Returns a new instance of Threaded.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/async/container/threaded.rb', line 28 def initialize(concurrency: 1, &block) @reactors = concurrency.times.collect do Async::Reactor.new end @threads = @reactors.collect do |reactor| Thread.new do Thread.current.abort_on_exception = true begin reactor.run(&block) rescue Interrupt # Exit cleanly. end end end end |
Instance Method Details
#stop ⇒ Object
46 47 48 49 |
# File 'lib/async/container/threaded.rb', line 46 def stop @reactors.each(&:stop) @threads.each(&:join) end |