Sha256: caed065742a9fa962bae6654e191bb11954a7aca2a9ce34ab72263376af97735
Contents?: true
Size: 748 Bytes
Versions: 1
Compression:
Stored size: 748 Bytes
Contents
module Bixby module Signal # Helper for trapping signals and handling them via a dedicated thread # # @param [String] *signals Signals to trap either as a space-separate string or array # @param [Block] block Callback when signal is trapped # # @return [Thread] def self.trap(*signals, &block) sigs = signals.flatten.map{ |s| s.split(/[\s,]/) }.flatten.sort.uniq trap_r, trap_w = IO.pipe sigs.each do |sig| Kernel.trap(sig) do trap_w.puts(sig) end end # handle signals from a dedicated thread Thread.new do while true sig = trap_r.readline.strip block.call(sig) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bixby-common-0.6.0 | lib/bixby-common/util/signal.rb |