Class: Mutiny::Isolation::Pipe

Inherits:
Struct
  • Object
show all
Defined in:
lib/mutiny/isolation/pipe.rb

Overview

An inter-process communication mechanism for sending and receiving (marshalled) data over an IO pipe

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#readerObject

Returns the value of attribute reader

Returns:

  • (Object)

    the current value of reader



5
6
7
# File 'lib/mutiny/isolation/pipe.rb', line 5

def reader
  @reader
end

#writerObject

Returns the value of attribute writer

Returns:

  • (Object)

    the current value of writer



5
6
7
# File 'lib/mutiny/isolation/pipe.rb', line 5

def writer
  @writer
end

Class Method Details

.with(&block) ⇒ Object



6
7
8
9
10
11
# File 'lib/mutiny/isolation/pipe.rb', line 6

def self.with(&block)
  IO.pipe(binmode: true) do |reader, writer|
    writer.binmode
    block.call(Pipe.new(reader, writer))
  end
end

Instance Method Details

#receiveObject



13
14
15
16
# File 'lib/mutiny/isolation/pipe.rb', line 13

def receive
  writer.close
  Marshal.load(reader.read)
end

#send(data) ⇒ Object



18
19
20
21
22
# File 'lib/mutiny/isolation/pipe.rb', line 18

def send(data)
  reader.close
  writer.write(Marshal.dump(data))
  writer.close
end