Fix exception on ^C

Stephen Paul Weber created

Defer the stop to happen outside of the trap handler so that EM won't
freak out about it.

Change summary

sgx-catapult.rb | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

Detailed changes

sgx-catapult.rb 🔗

@@ -1038,11 +1038,13 @@ at_exit do
 		server.start do
 			["INT", "TERM"].each do |sig|
 				trap(sig) do
-					puts 'Shutting down gateway...'
-					SGXcatapult.shutdown
+					EM.defer do
+						puts 'Shutting down gateway...'
+						SGXcatapult.shutdown
 
-					puts 'Gateway has terminated.'
-					EM.stop
+						puts 'Gateway has terminated.'
+						EM.stop
+					end
 				end
 			end
 		end