require "http/server" active_requests = 0 server = HTTP::Server.new do |context| active_requests += 1 sleep 60.seconds context.response.content_type = "text/plain" context.response.print "The time is: #{Time.now}\n" active_requests -= 1 end Signal::INT.trap do puts "Will stop in moment! (#{active_requests} active requests)" server.close if !server.closed? end server.bind_tcp "0.0.0.0", 8080, true puts "Listening on http://0.0.0.0:8080" server.listen until active_requests == 0 Fiber.yield end