Class: Async::Container::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/async/container/channel.rb

Direct Known Subclasses

Process, Thread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChannel

Returns a new instance of Channel.



28
29
30
# File 'lib/async/container/channel.rb', line 28

def initialize
	@in, @out = ::IO.pipe
end

Instance Attribute Details

#inObject (readonly)

Returns the value of attribute in.



32
33
34
# File 'lib/async/container/channel.rb', line 32

def in
  @in
end

#outObject (readonly)

Returns the value of attribute out.



33
34
35
# File 'lib/async/container/channel.rb', line 33

def out
  @out
end

Instance Method Details

#closeObject



43
44
45
46
# File 'lib/async/container/channel.rb', line 43

def close
	close_read
	close_write
end

#close_readObject



35
36
37
# File 'lib/async/container/channel.rb', line 35

def close_read
	@in.close
end

#close_writeObject



39
40
41
# File 'lib/async/container/channel.rb', line 39

def close_write
	@out.close
end

#receiveObject



48
49
50
51
52
53
54
55
56
# File 'lib/async/container/channel.rb', line 48

def receive
	if data = @in.gets
		begin
			return JSON.parse(data, symbolize_names: true)
		rescue
			return {line: data}
		end
	end
end