class Bootsnap::CLI::WorkerPool::Worker
Attributes
pid[R]
to_io[R]
Public Class Methods
new(jobs)
click to toggle source
# File lib/bootsnap/cli/worker_pool.rb, line 37 def initialize(jobs) @jobs = jobs @pipe_out, @to_io = IO.pipe(binmode: true) # Set the writer encoding to binary since IO.pipe only sets it for the reader. # https://github.com/rails/rails/issues/16514#issuecomment-52313290 @to_io.set_encoding(Encoding::BINARY) @pid = nil end
Public Instance Methods
close()
click to toggle source
# File lib/bootsnap/cli/worker_pool.rb, line 57 def close to_io.close end
spawn()
click to toggle source
# File lib/bootsnap/cli/worker_pool.rb, line 72 def spawn @pid = Process.fork do to_io.close work_loop exit!(0) end @pipe_out.close true end
work_loop()
click to toggle source
# File lib/bootsnap/cli/worker_pool.rb, line 61 def work_loop loop do job, *args = Marshal.load(@pipe_out) return if job == :exit @jobs.fetch(job).call(*args) end rescue IOError nil end
write(message, block: true)
click to toggle source
# File lib/bootsnap/cli/worker_pool.rb, line 47 def write(message, block: true) payload = Marshal.dump(message) if block to_io.write(payload) true else to_io.write_nonblock(payload, exception: false) != :wait_writable end end