class ProcessExecuter::MonitoredPipe

Stream data sent through a pipe to one or more writers

When a new MonitoredPipe is created, a pipe is created (via IO.pipe) and a thread is created to read data written to the pipe.

Data that is read from that pipe is written one or more writers passed to ‘#initialize`.

If any of the writers raise an exception, the monitoring thread will exit, the pipe will be closed, and the exception will be saved in ‘#exception`.

‘#close` must be called to ensure that (1) the pipe is closed, (2) all data is read from the pipe and written to the writers, and (3) the monitoring thread is killed.

@example Collect pipe data into a string

pipe_data = StringIO.new
begin
  pipe = MonitoredPipe.new(pipe_data)
  pipe.write("Hello World")
ensure
  pipe.close
end
pipe_data.string #=> "Hello World"

@example Collect pipe data into a string AND a file

pipe_data_string = StringIO.new
pipe_data_file = File.open("pipe_data.txt", "w")
begin
  pipe = MonitoredPipe.new(pipe_data_string, pipe_data_file)
  pipe.write("Hello World")
ensure
  pipe.close
end
pipe_data_string.string #=> "Hello World"
File.read("pipe_data.txt") #=> "Hello World"

@api public