Class: Async::Container::Threaded::Child::Instance
- Inherits:
-
Notify::Pipe
- Object
- Notify::Client
- Notify::Pipe
- Async::Container::Threaded::Child::Instance
- Defined in:
- lib/async/container/threaded.rb
Overview
Represents a running child thread from the point of view of the child thread.
Constant Summary
Constants inherited from Notify::Pipe
Class Method Summary collapse
-
.for(thread) ⇒ Object
Wrap an instance around the Thread instance from within the threaded child.
Instance Method Summary collapse
-
#as_json ⇒ Object
Generate a hash representation of the thread.
-
#exec(*arguments, ready: true, **options) ⇒ Object
Execute a child process using Process.spawn.
-
#initialize(io) ⇒ Instance
constructor
Initialize the child thread instance.
-
#name ⇒ Object
Get the name of the thread.
-
#name=(value) ⇒ Object
Set the name of the thread.
-
#to_json ⇒ Object
Generate a JSON representation of the thread.
Methods inherited from Notify::Pipe
Methods inherited from Notify::Client
#error!, #ready!, #reloading!, #restarting!, #status!, #stopping!
Constructor Details
#initialize(io) ⇒ Instance
Initialize the child thread instance.
55 56 57 58 59 |
# File 'lib/async/container/threaded.rb', line 55 def initialize(io) @thread = ::Thread.current super end |
Class Method Details
.for(thread) ⇒ Object
Wrap an instance around the Thread instance from within the threaded child.
46 47 48 49 50 |
# File 'lib/async/container/threaded.rb', line 46 def self.for(thread) instance = self.new(thread.out) return instance end |
Instance Method Details
#as_json ⇒ Object
Generate a hash representation of the thread.
64 65 66 67 68 69 70 |
# File 'lib/async/container/threaded.rb', line 64 def as_json(...) { process_id: ::Process.pid, thread_id: @thread.object_id, name: @thread.name, } end |
#exec(*arguments, ready: true, **options) ⇒ Object
Execute a child process using Process.spawn. In order to simulate Process.exec, an Exit instance is raised to propagage exit status. This creates the illusion that this method does not return (normally).
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/async/container/threaded.rb', line 93 def exec(*arguments, ready: true, **) if ready self.ready!(status: "(spawn)") else self.before_spawn(arguments, ) end begin pid = ::Process.spawn(*arguments, **) ensure _, status = ::Process.wait2(pid) raise Exit, status end end |
#name ⇒ Object
Get the name of the thread.
87 88 89 |
# File 'lib/async/container/threaded.rb', line 87 def name @thread.name end |
#name=(value) ⇒ Object
Set the name of the thread.
81 82 83 |
# File 'lib/async/container/threaded.rb', line 81 def name= value @thread.name = value end |
#to_json ⇒ Object
Generate a JSON representation of the thread.
75 76 77 |
# File 'lib/async/container/threaded.rb', line 75 def to_json(...) as_json.to_json(...) end |