I have the following code where the WEBrick instance is deployed, and I want to wait until we get together before continuing with the rest of the code:
require 'webrick'
pid = fork do
server = WEBrick::HTTPServer.new({:Port => 3333, :BindAddress => "localhost"})
trap("INT") { server.shutdown }
sleep 10
server.start
end
puts `curl localhost:3333 --max-time 1`
Process.kill('INT', pid)
So, how can I wait for the plug to finish, or even better, until WEBrick is ready to accept connections? I found a piece of code where they deal with IO.pipeboth the reader and the writer. But it does not wait for webrick to load.
Unfortunately, I did not find anything for this particular case. Hope someone can help.
23tux source
share