Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module AgentDispatch
class Loader
def self.run!
new.run!
end
def run!
future = master.future.run # It's a celluloid example here
while read_trap_io
raise Interrupt
end
rescue Interrupt
# clean up and exit
end
private
TRAPS = %w(INT TERM)
attr_reader :self_read, :self_write
def initialize
@self_read, @self_write = IO.pipe
setup_trap_signals
end
def setup_trap_signals
TRAPS.each do |trap|
Signal.trap(trap) do
self_write.puts(trap)
end
end
end
def read_trap_io
@readable_io = IO.select([self_read])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment