class Thread
Represents a running child thread from the point of view of the parent container.
Nested
Definitions
def initialize(name: nil)
Initialize the thread.
Signature
-
parameter
name
String
The name to use for the child thread.
Implementation
def initialize(name: nil)
super()
@status = nil
@thread = yield(self)
@thread.report_on_exception = false
@thread.name = name
@waiter = ::Thread.new do
begin
@thread.join
rescue Exit => exit
finished(exit.error)
rescue Interrupt
# Graceful shutdown.
finished
rescue Exception => error
finished(error)
else
finished
end
end
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 to_s
A human readable representation of the thread.
Signature
-
returns
String
Implementation
def to_s
"\#<#{self.class} #{@thread.name}>"
end
def close
Invoke #terminate!
and then #wait
for the child thread to exit.
Implementation
def close
self.terminate!
self.wait
ensure
super
end
def interrupt!
Raise Interrupt = ::Interrupt
in the child thread.
Implementation
def interrupt!
@thread.raise(Interrupt)
end
def terminate!
Raise class Async::Container::Terminate
in the child thread.
Implementation
def terminate!
@thread.raise(Terminate)
end
def wait
Wait for the thread to exit and return he exit status.
Signature
-
returns
Status
Implementation
def wait
if @waiter
@waiter.join
@waiter = nil
end
return @status
end
def finished(error = nil)
Invoked by the @waiter thread to indicate the outcome of the child thread.
Implementation
def finished(error = nil)
if error
Console.logger.error(self) {error}
end
@status = Status.new(error)
self.close_write
end