Class: JSCommander::PipeBroker::PipeQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/jscmd/pipebroker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, w) ⇒ PipeQueue

Returns a new instance of PipeQueue.



6
7
8
# File 'lib/jscmd/pipebroker.rb', line 6

def initialize(r, w)
  @reader, @writer = [r, w]
end

Instance Attribute Details

#readerObject (readonly)

Returns the value of attribute reader.



4
5
6
# File 'lib/jscmd/pipebroker.rb', line 4

def reader
  @reader
end

#writerObject (readonly)

Returns the value of attribute writer.



4
5
6
# File 'lib/jscmd/pipebroker.rb', line 4

def writer
  @writer
end

Instance Method Details

#closeObject



20
21
22
23
# File 'lib/jscmd/pipebroker.rb', line 20

def close
  @reader.close
  @writer.close
end

#popObject



15
16
17
18
# File 'lib/jscmd/pipebroker.rb', line 15

def pop
  size = @reader.read(4).unpack("N")[0]
  Marshal.load(@reader.read(size))
end

#push(obj) ⇒ Object



10
11
12
13
# File 'lib/jscmd/pipebroker.rb', line 10

def push(obj)
  data = Marshal.dump(obj)
  @writer.write([data.size].pack("N") + data)
end