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.



26
27
28
# File 'lib/async/container/channel.rb', line 26

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

Instance Attribute Details

#inObject (readonly)

Returns the value of attribute in.



30
31
32
# File 'lib/async/container/channel.rb', line 30

def in
  @in
end

#outObject (readonly)

Returns the value of attribute out.



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

def out
  @out
end

Instance Method Details

#closeObject



41
42
43
44
# File 'lib/async/container/channel.rb', line 41

def close
	close_read
	close_write
end

#close_readObject



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

def close_read
	@in.close
end

#close_writeObject



37
38
39
# File 'lib/async/container/channel.rb', line 37

def close_write
	@out.close
end

#receiveObject



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

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