class Instance
Represents a running child thread from the point of view of the child thread.
Definitions
def self.for(thread)
Wrap an instance around the Thread
instance from within the threaded child.
Signature
-
parameter
thread
Thread
The thread intance to wrap.
Implementation
def self.for(thread)
instance = self.new(thread.out)
return instance
end
def initialize(io)
Initialize the child thread instance.
Signature
-
parameter
io
IO
The IO object to use for communication with the parent.
Implementation
def initialize(io)
@thread = ::Thread.current
super
end
def as_json(...)
Generate a hash representation of the thread.
Signature
-
returns
Hash
The thread as a hash, including
process_id
,thread_id
, andname
.
Implementation
def as_json(...)
{
process_id: ::Process.pid,
thread_id: @thread.object_id,
name: @thread.name,
}
end
def to_json(...)
Generate a JSON representation of the thread.
Signature
-
returns
String
The thread as JSON.
Implementation
def to_json(...)
as_json.to_json(...)
end
def name= value
Set the name of the thread.
Signature
-
parameter
value
String
The name to set.
Implementation
def name= value
@thread.name = value
end
def name
Get the name of the thread.
Signature
-
returns
String
Implementation
def name
@thread.name
end
def exec(*arguments, ready: true, **options)
Execute a child process using ::Process.spawn
. In order to simulate ::Process.exec
, an class Async::Container::Threaded::Child::Exit
instance is raised to propagage exit status.
This creates the illusion that this method does not return (normally).
Implementation
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