|
9 | 9 | module Async |
10 | 10 | module Container |
11 | 11 | module Forked |
| 12 | + # Represents a child process managed by a forked container. |
12 | 13 | class Child < Container::Child |
| 14 | + # Start a child process using `fork`. |
| 15 | + # @parameter channel [Channel] The notification channel for the child. |
| 16 | + # @parameter name [String | Nil] The optional child name. |
| 17 | + # @parameter options [Hash] Additional child options. |
| 18 | + # @yields {|instance| ...} The child process body. |
| 19 | + # @parameter instance [Instance] The child-side instance interface. |
| 20 | + # @returns [Child] The forked child process. |
13 | 21 | def self.call(channel: Channel.new, name: nil, **options, &block) |
14 | 22 | process_id = ::Thread.new do |
15 | 23 | ::Process.fork do |
@@ -39,6 +47,10 @@ def self.call(channel: Channel.new, name: nil, **options, &block) |
39 | 47 | return self.new(process_id, channel, name: name, **options) |
40 | 48 | end |
41 | 49 |
|
| 50 | + # Initialize the child process wrapper. |
| 51 | + # @parameter process_id [Integer] The process identifier. |
| 52 | + # @parameter channel [Channel] The notification channel for the child. |
| 53 | + # @parameter options [Hash] Additional child options. |
42 | 54 | def initialize(process_id, channel, **options) |
43 | 55 | @process_id = process_id |
44 | 56 | @status = nil |
@@ -78,6 +90,9 @@ def restart! |
78 | 90 | end |
79 | 91 | end |
80 | 92 |
|
| 93 | + # Reap the child process. |
| 94 | + # @parameter timeout [Numeric | Nil] The maximum time to wait for the process to exit. |
| 95 | + # @returns [::Process::Status | Nil] The process status, or `nil` if the timeout expired. |
81 | 96 | def reap(timeout = nil) |
82 | 97 | unless @status |
83 | 98 | if timeout |
|
0 commit comments