Class: Bbq::Spawn::CoordinatedExecutor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bbq/spawn.rb

Instance Method Summary collapse

Constructor Details

#initialize(executor, options = {}) ⇒ CoordinatedExecutor

Returns a new instance of CoordinatedExecutor.



27
28
29
30
31
32
33
34
35
36
# File 'lib/bbq/spawn.rb', line 27

def initialize(executor, options = {})
  @executor = executor
  @timeout  = options.fetch(:timeout, 10)
  @banner   = options[:banner]
  @host     = options[:host]
  @port     = options[:port]
  @url      = options[:url]

  @reader, @writer = IO.pipe
end

Instance Method Details

#joinObject



44
45
46
47
48
49
50
51
# File 'lib/bbq/spawn.rb', line 44

def join
  Timeout.timeout(@timeout) do
    wait_for_io       if @banner
    wait_for_socket   if @port and @host
    wait_for_response if @url
  end
rescue Timeout::Error
end

#startObject



38
39
40
41
42
# File 'lib/bbq/spawn.rb', line 38

def start
  @executor.io.stdout = @executor.io.stderr = @writer
  @executor.start
  @writer.close
end