class BioDSL::Stream

Class for Inter Process Communication between forked processes using msgpack to serialize and deserialize objects.

Public Class Methods

new(io) click to toggle source
# File lib/BioDSL/stream.rb, line 47
def initialize(io)
  @io = io
end
pipe() click to toggle source

Create a pair of connected pipe endpoints. The connection uses msgpack allowing objects to be written and read.

Stream.pipe -> [read_io, write_io]

# File lib/BioDSL/stream.rb, line 41
def self.pipe
  read, write = IO.pipe(Encoding::BINARY)

  [new(read), new(write)]
end

Public Instance Methods

<<(obj)
Alias for: write
close() click to toggle source
# File lib/BioDSL/stream.rb, line 51
def close
  @io.close
end
closed?() click to toggle source
# File lib/BioDSL/stream.rb, line 55
def closed?
  @io.closed?
end
each() { |read until eof?| ... } click to toggle source
# File lib/BioDSL/stream.rb, line 59
def each
  yield read until @io.eof?
end
read() click to toggle source
# File lib/BioDSL/stream.rb, line 63
def read
  size = @io.read(4)
  fail EOFError unless size
  size = size.unpack('I').first
  msg  = @io.read(size)
  MessagePack.unpack(msg, symbolize_keys: true)
end
write(obj) click to toggle source
# File lib/BioDSL/stream.rb, line 71
def write(obj)
  msg = MessagePack.pack(obj)
  @io.write([msg.size].pack('I'))
  @io.write(msg)
end
Also aliased as: <<