class Async::Container::Threaded::Child::Instance

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

def self.for(thread)

@parameter thread [Thread] The thread intance to wrap.
Wrap an instance around the {Thread} instance from within the threaded child.
def self.for(thread)
	instance = self.new(thread.out)
	
	return instance
end

def as_json(...)

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

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

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

This creates the illusion that this method does not return (normally).
Execute a child process using {::Process.spawn}. In order to simulate {::Process.exec}, an {Exit} instance is raised to propagage exit status.
def exec(*arguments, ready: true, **options)
	if ready
		self.ready!(status: "(spawn)")
	else
		self.before_spawn(arguments, options)
	end
	
	begin
		pid = ::Process.spawn(*arguments, **options)
	ensure
		_, status = ::Process.wait2(pid)
		
		raise Exit, status
	end
end

def initialize(io)

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

Initialize the child thread instance.
def initialize(io)
	@thread = ::Thread.current
	
	super
end

def name

@returns [String]
Get the name of the thread.
def name
	@thread.name
end

def name= value

@parameter value [String] The name to set.
Set the name of the thread.
def name= value
	@thread.name = value
end

def to_json(...)

@returns [String] The thread as JSON.

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