Class: Phobos::CLI::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/phobos/cli/runner.rb

Constant Summary collapse

SIGNALS =
[:INT, :TERM, :QUIT].freeze

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



8
9
10
11
12
# File 'lib/phobos/cli/runner.rb', line 8

def initialize
  @signal_queue = []
  @reader, @writer = IO.pipe
  @executor = Phobos::Executor.new
end

Instance Method Details

#run!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/phobos/cli/runner.rb', line 14

def run!
  setup_signals
  executor.start

  loop do
    case signal_queue.pop
    when *SIGNALS
      executor.stop
      break
    else
      ready = IO.select([reader, writer])

      # drain the self-pipe so it won't be returned again next time
      reader.read_nonblock(1) if ready[0].include?(reader)
    end
  end
end