Async::ContainerSourceAsyncContainerChannel

class Channel

Provides a basic multi-thread/multi-process uni-directional communication channel.

Definitions

def initialize(timeout: 1.0)

Initialize the channel using a pipe.

Implementation

def initialize(timeout: 1.0)
	@in, @out = ::IO.pipe
	@in.timeout = timeout
end

attr :in

The input end of the pipe.

Signature

attribute IO

attr :out

The output end of the pipe.

Signature

attribute IO

def close_read

Close the input end of the pipe.

Implementation

def close_read
	@in.close
end

def close_write

Close the output end of the pipe.

Implementation

def close_write
	@out.close
end

def close

Close both ends of the pipe.

Implementation

def close
	close_read
	close_write
end

def receive

Receive an object from the pipe. Internally, prefers to receive newline formatted JSON, otherwise returns a hash table with a single key :line which contains the line of data that could not be parsed as JSON.

Signature

returns Hash

Implementation

def receive
	if data = @in.gets
		return JSON.parse(data, symbolize_names: true)
	end
rescue => error
	Console.error(self, "Error during channel receive!", error)
	return nil
end