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

Version Path
polyphony-0.79 lib/polyphony/adapters/process.rb
polyphony-0.78 lib/polyphony/adapters/process.rb
polyphony-0.77 lib/polyphony/adapters/process.rb
polyphony-0.76 lib/polyphony/adapters/process.rb
polyphony-0.75 lib/polyphony/adapters/process.rb
polyphony-0.74 lib/polyphony/adapters/process.rb
polyphony-0.73.1 lib/polyphony/adapters/process.rb
polyphony-0.73 lib/polyphony/adapters/process.rb
polyphony-0.72 lib/polyphony/adapters/process.rb
polyphony-0.71 lib/polyphony/adapters/process.rb
polyphony-0.70 lib/polyphony/adapters/process.rb
polyphony-0.69 lib/polyphony/adapters/process.rb
polyphony-0.68 lib/polyphony/adapters/process.rb
polyphony-0.67 lib/polyphony/adapters/process.rb
polyphony-0.66 lib/polyphony/adapters/process.rb
polyphony-0.65 lib/polyphony/adapters/process.rb
polyphony-0.64 lib/polyphony/adapters/process.rb
polyphony-0.63 lib/polyphony/adapters/process.rb
polyphony-0.62 lib/polyphony/adapters/process.rb
polyphony-0.61 lib/polyphony/adapters/process.rb