Sha256: 6c03b4ade3ede2b27d752253da088ad193e276dee8ad60c293b4c44da9609a6e

Contents?: true

Size: 690 Bytes

Versions: 6

Compression:

Stored size: 690 Bytes

Contents

module TestR
module Client

  class Receiver < Thread
    def initialize *popen_args
      (@io = IO.popen(*popen_args)).sync = true
      super() { loop { yield @io.gets } }
    end

    def quit
      kill # stop receive loop
      Process.kill :SIGTERM, @io.pid
      Process.wait @io.pid # reap zombie
      @io.close # prevent further I/O
    end
  end

  class Transceiver < Receiver
    def initialize *popen_args
      @io_write_lock = Mutex.new
      popen_args[1] = 'w+'
      super
    end

    def send command
      @io_write_lock.synchronize do
        warn "#{caller[2]} SEND #{command.inspect}" if $DEBUG
        @io.puts JSON.dump(command)
      end
    end
  end

end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
testr-14.3.0 lib/testr/client.rb
testr-14.2.0 lib/testr/client.rb
testr-14.1.3 lib/testr/client.rb
testr-14.1.2 lib/testr/client.rb
testr-14.1.1 lib/testr/client.rb
testr-14.1.0 lib/testr/client.rb