Sha256: 8b74e5af0c7174074185f4b3dd73024f1467f1c23772602ec355a8de3881848b

Contents?: true

Size: 738 Bytes

Versions: 4

Compression:

Stored size: 738 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)
        Thread.current.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)
        Thread.current.backend.waitpid(pid)
      rescue Errno::ERSCH
        # ignore
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
polyphony-0.50.1 lib/polyphony/adapters/process.rb
polyphony-0.50.0 lib/polyphony/adapters/process.rb
polyphony-0.49.2 lib/polyphony/adapters/process.rb
polyphony-0.49.1 lib/polyphony/adapters/process.rb