Class: Cod::BidirPipe

Inherits:
Channel show all
Defined in:
lib/cod/bidir_pipe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Channel

#client, #interact, #service

Constructor Details

#initialize(serializer = nil, pipe_pair = nil) ⇒ BidirPipe

Returns a new instance of BidirPipe.



8
9
10
11
# File 'lib/cod/bidir_pipe.rb', line 8

def initialize(serializer=nil, pipe_pair=nil)
  @serializer = serializer || SimpleSerializer.new
  @r, @w = pipe_pair || [Cod.pipe(@serializer), Cod.pipe(@serializer)]
end

Instance Attribute Details

#rObject (readonly)

The Cod::Pipe instance we’re currently #get’ting from.



6
7
8
# File 'lib/cod/bidir_pipe.rb', line 6

def r
  @r
end

#wObject (readonly)

The Cod::Pipe instance we’re currently #put’ting to.



4
5
6
# File 'lib/cod/bidir_pipe.rb', line 4

def w
  @w
end

Instance Method Details

#closeObject



21
22
23
24
# File 'lib/cod/bidir_pipe.rb', line 21

def close
  r.close
  w.close
end

#getObject



17
18
19
# File 'lib/cod/bidir_pipe.rb', line 17

def get
  r.get
end

#put(msg) ⇒ Object



13
14
15
# File 'lib/cod/bidir_pipe.rb', line 13

def put(msg)
  w.put(msg)
end

#swap!Object

Swaps the end of this pipe around.



28
29
30
# File 'lib/cod/bidir_pipe.rb', line 28

def swap!
  @r, @w = w, r
end