Sha256: 89839259f169ef8a85c8f018c2c481fcef780200b54d88fa803a445c085dd956
Contents?: true
Size: 743 Bytes
Versions: 32
Compression:
Stored size: 743 Bytes
Contents
# frozen_string_literal: true module Polyphony # Process patches module Process class << self def watch(cmd = nil, &block) terminated = nil pid = cmd ? Kernel.spawn(cmd) : Polyphony.fork(&block) Polyphony.backend_waitpid(pid) terminated = true ensure kill_process(pid) unless terminated || pid.nil? end def kill_process(pid) cancel_after(5) do kill_and_await('TERM', pid) end rescue Polyphony::Cancel kill_and_await(-9, pid) end def kill_and_await(sig, pid) ::Process.kill(sig, pid) Polyphony.backend_waitpid(pid) rescue Errno::ESRCH # process doesn't exist end end end end
Version data entries
32 entries across 32 versions & 1 rubygems