lib/async/container/threaded.rb in async-container-0.14.1 vs lib/async/container/threaded.rb in async-container-0.15.0
- old
+ new
@@ -19,17 +19,17 @@
# THE SOFTWARE.
require 'async/reactor'
require 'thread'
-require_relative 'controller'
+require_relative 'generic'
require_relative 'statistics'
module Async
module Container
# Manages a reactor within one or more threads.
- class Threaded < Controller
+ class Threaded < Generic
class Instance
def initialize(thread)
@thread = thread
end
@@ -57,15 +57,12 @@
def initialize
super
@threads = []
@running = true
- @statistics = Statistics.new
end
- attr :statistics
-
def spawn(name: nil, restart: false, &block)
@statistics.spawn!
thread = ::Thread.new do
thread = ::Thread.current
@@ -96,22 +93,21 @@
@threads << thread
return self
end
- def wait(forever = false)
+ def sleep(duration)
+ Kernel::sleep(duration)
+ end
+
+ def wait
@threads.each(&:join)
@threads.clear
-
- sleep if forever
- rescue Interrupt
- # Graceful exit.
end
# Gracefully shut down all reactors.
def stop(graceful = true)
@running = false
- super
if graceful
@threads.each{|thread| thread.raise(Interrupt)}
else
@threads.each(&:kill)