Sha256: 2dcddb2c0a3508910a3193ff057838f3c584d7fadba73f18fd2f83903cf10340
Contents?: true
Size: 695 Bytes
Versions: 13
Compression:
Stored size: 695 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) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems