Sha256: 6887370acab35cc304ed6e4ec92478990e784be60cfdf9abec51cff3ffabf488
Contents?: true
Size: 788 Bytes
Versions: 1
Compression:
Stored size: 788 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 Thread.new do block.call(sig) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bixby-common-0.6.1 | lib/bixby-common/util/signal.rb |