class Zold::Farmers::Fork

In a child process using fork

Public Class Methods

new(log: Log::NULL) click to toggle source
# File lib/zold/node/farmers.rb, line 58
def initialize(log: Log::NULL)
  @log = log
end

Public Instance Methods

up(score) click to toggle source
# File lib/zold/node/farmers.rb, line 62
      def up(score)
        start = Time.now
        stdout, stdin = IO.pipe
        pid = Process.fork do
          stdin.puts(score.next)
        end
        at_exit { Farmers.kill(@log, pid, start) }
        Process.wait
        stdin.close
        text = stdout.read.strip
        stdout.close
        raise "No score was calculated in the process ##{pid} in #{Age.new(start)}" if text.empty?
        after = Score.parse(text)
        @log.debug("Next score #{after.value}/#{after.strength} found in proc ##{pid} \
for #{after.host}:#{after.port} in #{Age.new(start)}: #{after.suffixes}")
        after
      end