class Async::Container::Forked::Child::Instance

Represents a running child process from the point of view of the child process.

def self.for(process)

@parameter process [Process] The process intance to wrap.
Wrap an instance around the {Process} instance from within the forked child.
def self.for(process)
	instance = self.new(process.out)
	
	# The child process won't be reading from the channel:
	process.close_read
	
	instance.name = process.name
	
	return instance
end

def as_json(...)

@returns [Hash] The process as a hash, including `process_id` and `name`.

Generate a hash representation of the process.
def as_json(...)
	{
		process_id: ::Process.pid,
		name: @name,
	}
end

def exec(*arguments, ready: true, **options)

@parameter options [Hash] Additional options to pass to {::Process.exec}.
@parameter ready [Boolean] If true, informs the parent process that the child is ready. Otherwise, the child process will need to use a notification protocol to inform the parent process that it is ready.
@parameter arguments [Array] The arguments to pass to the new process.

This method replaces the child process with the new executable, thus this method never returns.
Replace the current child process with a different one. Forwards arguments and options to {::Process.exec}.
def exec(*arguments, ready: true, **options)
	if ready
		self.ready!(status: "(exec)")
	else
		self.before_spawn(arguments, options)
	end
	
	::Process.exec(*arguments, **options)
end

def initialize(io)

@parameter io [IO] The IO object to use for communication.

Initialize the child process instance.
def initialize(io)
	super
	
	@name = nil
end

def name

@returns [String] The name of the process.
def name
	@name
end

def name= value

@parameter value [String] The name of the process.

Set the process title to the specified value.
def name= value
	@name = value
	
	# This sets the process title to an empty string if the name is nil:
	::Process.setproctitle(@name.to_s)
end

def to_json(...)

@returns [String] The process as JSON.

Generate a JSON representation of the process.
def to_json(...)
	as_json.to_json(...)
end