Skip to content

Instantly share code, notes, and snippets.

@sb8244
Created April 10, 2015 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sb8244/a11c1fb5234a3e89d191 to your computer and use it in GitHub Desktop.
Save sb8244/a11c1fb5234a3e89d191 to your computer and use it in GitHub Desktop.
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