class Concurrent::RubySingleThreadExecutor
@!macro single_thread_executor
def alive?
def alive? @thread && @thread.alive? end
def execute(*args, &task)
def execute(*args, &task) supervise @queue << [args, task] end
def initialize(opts = {})
- See: http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html -
See: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html -
See: http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html -
def initialize(opts = {}) @queue = Queue.new @thread = nil init_executor end
def kill_execution
def kill_execution @queue.clear @thread.kill if alive? end
def new_worker_thread
def new_worker_thread Thread.new do Thread.current.abort_on_exception = false work end end
def shutdown_execution
def shutdown_execution @queue << :stop stopped_event.set unless alive? end
def supervise
def supervise @thread = new_worker_thread unless alive? end
def work
def work loop do task = @queue.pop break if task == :stop begin task.last.call(*task.first) rescue => ex # let it fail end end stopped_event.set end