class Concurrent::SimpleExecutorService
@note Intended for use primarily in testing and debugging.
lead to suboptimal performance.
executor implementation. In production this executor will likely
debugging because it decouples the using code from the underlying
resource pooling. This can be very beneficial during testing and
and management is expensive in Ruby and this executor performs no
library. It exists mainly for testing an debugging. Thread creation
This is perhaps the most inefficient executor service in this
independently operating thread.
An executor service in which every operation spawns a new,
def self.<<(task)
def self.<<(task) post(&task) self end
def self.post(*args)
def self.post(*args) raise ArgumentError.new('no block given') unless block_given? Thread.new(*args) do Thread.current.abort_on_exception = false yield(*args) end true end
def <<(task)
def <<(task) post(&task) self end
def kill
def kill @running.make_false @stopped.set true end
def ns_initialize
def ns_initialize @running = Concurrent::AtomicBoolean.new(true) @stopped = Concurrent::Event.new @count = Concurrent::AtomicFixnum.new(0) end
def post(*args, &task)
def post(*args, &task) raise ArgumentError.new('no block given') unless block_given? return false unless running? @count.increment Thread.new(*args) do Thread.current.abort_on_exception = false begin yield(*args) ensure @count.decrement @stopped.set if @running.false? && @count.value == 0 end end end
def running?
def running? @running.true? end
def shutdown
def shutdown @running.make_false @stopped.set if @count.value == 0 true end
def shutdown?
def shutdown? @stopped.set? end
def shuttingdown?
def shuttingdown? @running.false? && ! @stopped.set? end
def wait_for_termination(timeout = nil)
def wait_for_termination(timeout = nil) @stopped.wait(timeout) end