Class: Droonga::Command::DroongaEngine::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/command/droonga_engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loop) ⇒ CommandRunner

Returns a new instance of CommandRunner.



490
491
492
493
494
# File 'lib/droonga/command/droonga_engine.rb', line 490

def initialize(loop)
  @loop = loop
  @commands = []
  @on_command = nil
end

Instance Attribute Details

#on_command=(value) ⇒ Object (writeonly)

Sets the attribute on_command

Parameters:

  • value

    the value to set the attribute on_command to.



489
490
491
# File 'lib/droonga/command/droonga_engine.rb', line 489

def on_command=(value)
  @on_command = value
end

Instance Method Details

#push_command(command) ⇒ Object



518
519
520
521
522
523
# File 'lib/droonga/command/droonga_engine.rb', line 518

def push_command(command)
  return if @async_watcher.nil?
  first_command_p = @commands.empty?
  @commands << command
  @async_watcher.signal if first_command_p
end

#startObject



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/droonga/command/droonga_engine.rb', line 496

def start
  @async_watcher = Coolio::AsyncWatcher.new
  on_signal = lambda do
    commands = @commands.uniq
    @commands.clear
    until commands.empty?
      command = commands.shift
      @on_command.call(command) if @on_command
    end
  end
  @async_watcher.on_signal do
    on_signal.call
  end
  @loop.attach(@async_watcher)
end

#stopObject



512
513
514
515
516
# File 'lib/droonga/command/droonga_engine.rb', line 512

def stop
  return if @async_watcher.nil?
  @async_watcher.detach
  @async_watcher = nil
end