class ParallelRSpec::Channel
Adapted from nitra. Copyright 2012-2013 Roger Nesbitt, Powershop Limited, YouDo Limited. MIT licence.
Constants
- ProtocolInvalidError
Attributes
Public Class Methods
Source
# File lib/parallel_rspec/channel.rb, line 10 def initialize(rd, wr) @rd = rd @wr = wr @rd.binmode @wr.binmode end
Source
# File lib/parallel_rspec/channel.rb, line 17 def self.pipe c_rd, s_wr = IO.pipe("ASCII-8BIT", "ASCII-8BIT") s_rd, c_wr = IO.pipe("ASCII-8BIT", "ASCII-8BIT") [new(c_rd, c_wr), new(s_rd, s_wr)] end
Source
# File lib/parallel_rspec/channel.rb, line 23 def self.read_select(channels) fds = IO.select(channels.collect(&:rd)) fds.first.collect do |fd| channels.detect {|c| c.rd == fd} end end
Public Instance Methods
Source
# File lib/parallel_rspec/channel.rb, line 35 def read return unless line = rd.gets if result = line.strip.match(/\ACOMMAND,(\d+)\z/) data = rd.read(result[1].to_i) Marshal.load(data) else raise ProtocolInvalidError, "Expected command length line, got #{line.inspect}" end end
Source
# File lib/parallel_rspec/channel.rb, line 45 def write(data) encoded = Marshal.dump(data) wr.write("COMMAND,#{encoded.bytesize}\n") wr.write(encoded) wr.flush rescue Errno::EPIPE raise if raise_epipe_on_write_error end