Class: Async::Container::Thread::Instance
- Inherits:
-
Notify::Pipe
- Object
- Notify::Client
- Notify::Pipe
- Async::Container::Thread::Instance
- Defined in:
- lib/async/container/thread.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 Async::Container::Thread instance from within the threaded child.
Instance Method Summary collapse
-
#exec(*arguments, ready: true, **options) ⇒ Object
Execute a child process using Process.spawn.
-
#initialize(io) ⇒ Instance
constructor
A new instance of Instance.
-
#name ⇒ Object
Get the name of the thread.
-
#name=(value) ⇒ Object
Set the name of the thread.
Methods inherited from Notify::Pipe
Methods inherited from Notify::Client
#error!, #ready!, #reloading!, #restarting!, #status!, #stopping!
Constructor Details
#initialize(io) ⇒ Instance
Returns a new instance of Instance.
62 63 64 65 66 67 |
# File 'lib/async/container/thread.rb', line 62 def initialize(io) @name = nil @thread = ::Thread.current super end |
Class Method Details
.for(thread) ⇒ Object
Wrap an instance around the Async::Container::Thread instance from within the threaded child.
56 57 58 59 60 |
# File 'lib/async/container/thread.rb', line 56 def self.for(thread) instance = self.new(thread.out) return instance end |
Instance Method Details
#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).
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/async/container/thread.rb', line 83 def exec(*arguments, ready: true, **) if ready self.ready!(status: "(spawn)") if ready else self.before_spawn(arguments, ) end begin # TODO prefer **options... but it doesn't support redirections on < 2.7 pid = ::Process.spawn(*arguments, ) ensure _, status = ::Process.wait2(pid) raise Exit, status end end |
#name ⇒ Object
Get the name of the thread.
77 78 79 |
# File 'lib/async/container/thread.rb', line 77 def name @thread.name end |
#name=(value) ⇒ Object
Set the name of the thread.
71 72 73 |
# File 'lib/async/container/thread.rb', line 71 def name= value @thread.name = value end |