class Async::Container::Generic
def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block)
@parameter key [Symbol] A key used for reloading child instances.
@parameter restart [Boolean] Whether to restart the child instance if it fails.
@parameter name [String] The name of the child instance.
Spawn a child instance into the container.
def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block) name ||= UNNAMED if mark?(key) Console.debug(self) {"Reusing existing child for #{key}: #{name}"} return false end @statistics.spawn! fiber do while @running child = self.start(name, &block) state = insert(key, child) # If a health check is specified, we will monitor the child process and terminate it if it does not update its state within the specified time. if health_check_timeout age_clock = state[:age] = Clock.start end begin status = @group.wait_for(child) do |message| case message when :health_check! if health_check_timeout&.<(age_clock.total) health_check_failed!(child, age_clock, health_check_timeout) end else state.update(message) age_clock&.reset! end end ensure delete(key, child) end if status.success? Console.debug(self) {"#{child} exited with #{status}"} else @statistics.failure! Console.error(self, status: status) end if restart @statistics.restart! else break end end end.resume return true end