class Async::Container::Threaded::Child::Instance
Represents a running child thread from the point of view of the child thread.
def self.for(thread)
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(...)
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)
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)
Initialize the child thread instance.
def initialize(io) @thread = ::Thread.current super end
def name
Get the name of the thread.
def name @thread.name end
def name= value
Set the name of the thread.
def name= value @thread.name = value end
def to_json(...)
Generate a JSON representation of the thread.
def to_json(...) as_json.to_json(...) end