Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
refactor: Move signal handling to its own class
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloboeira committed Nov 7, 2016
1 parent a5763a5 commit 6e91312
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/bojack/event_loop/signal.cr
@@ -0,0 +1,20 @@
require "socket"
require "../logger"

module BoJack
module EventLoop
class Signal
@logger : BoJack::Logger = BoJack::Logger.instance

def watch(server : TCPServer)
::Signal::INT.trap do
@logger.info("BoJack is going to take a rest")

server.close

exit
end
end
end
end
end
6 changes: 1 addition & 5 deletions src/bojack/server.cr
Expand Up @@ -37,11 +37,7 @@ module BoJack
end

private def handle_signal_trap
Signal::INT.trap do
@logger.info("BoJack is going to take a rest")
@server.close
exit
end
BoJack::EventLoop::Signal.new.watch(@server)
end

def self.memory
Expand Down

0 comments on commit 6e91312

Please sign in to comment.