Created
April 10, 2015 21:07
-
-
Save sb8244/a11c1fb5234a3e89d191 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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