class Ruactor::Dispatcher

Attributes

queue[R]

Public Class Methods

new() click to toggle source
# File lib/ruactor.rb, line 19
def initialize()
  @queue = Queue.new
  @started = false
  @lock = Mutex.new
end

Public Instance Methods

start() click to toggle source
# File lib/ruactor.rb, line 25
def start
  @lock.synchronize {
    unless started?
      @threads = []
      5.times do
        thread = Thread.new do
          loop do
            obj, method, args, block = @queue.pop
            obj.send method, *args, &block
          end
        end
        @threads << thread
      end
      @started = true
    end
  }
end
started?() click to toggle source
# File lib/ruactor.rb, line 51
def started?
  @started
end
stop() click to toggle source
# File lib/ruactor.rb, line 43
def stop
  @lock.synchronize {
    @threads.each { |t| t.exit }
    @threads.each { |t| t.join }
    @started = false
  }
end
stopped?() click to toggle source
# File lib/ruactor.rb, line 55
def stopped?
  !started?
end