Skip to content

Instantly share code, notes, and snippets.

@dbalatero
Created June 10, 2009 16:47
Show Gist options
  • Save dbalatero/127339 to your computer and use it in GitHub Desktop.
Save dbalatero/127339 to your computer and use it in GitHub Desktop.
# current HEAD
require 'sinatra/base'
class MyApp < Sinatra::Base
get '/' do
'test'
end
end
app = Sinatra.new(MyApp) do
end
thread = Thread.new(app) do |a|
a.run!
end
while !app.running?
# block until the app spins up...
end
# This never gets here.
puts "The Sinatra app has booted up finally!"
thread.join
# wait for ctrl+c for exit.
For the fix: http://github.com/dbalatero/sinatra/commit/7d492b2311502ebe398a1fa860c13920640cf29b
The reason that the relevant line in that commit had to move is because Sinatra
never makes it past the handler.run() Proc, as calling handler.run() will join
on the Thin/Mongrel/etc server until someone sends a Ctrl + C to stop it.
By setting running to true inside the Proc, we are guaranteed that to happen before
blocking happens on the web server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment