Skip to content

Instantly share code, notes, and snippets.

@skanev
Created September 19, 2010 10:40
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 skanev/586649 to your computer and use it in GitHub Desktop.
Save skanev/586649 to your computer and use it in GitHub Desktop.
module Sunglass
module Slave
class WEBrick
def initialize(application, port)
@application = application
@port = port
@mutex = Mutex.new
@condition = ConditionVariable.new
end
def start
@mutex.synchronize do
Thread.new do
Rack::Handler::WEBrick.run(@application, webrick_options) { |server| @server = server }
end
@condition.wait @mutex
end
end
def stop
@mutex.synchronize do
@server.shutdown
@condition.wait @mutex
end
end
private
def webrick_options
{
:Port => @port,
:Logger => Logger.new('/dev/null'),
:AccessLog => [],
:StartCallback => lambda { @mutex.synchronize { @condition.signal } },
:StopCallback => lambda { @mutex.synchronize { @condition.signal } },
}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment