我有以下代码:
require 'rubygems'
require 'eventmachine'
require 'em-http'
require 'sinatra/base'
require 'sinatra/async'
class Api < Sinatra::Base
register Sinatra::Async
aget '/1' do
EventMachine.run {
http = EventMachine::HttpRequest.new( "http://www.google.com").get(:timeout => 5)
http.callback { puts "h2" ;ret_val = http.response; EventMachine.stop}
http.errback {puts "was h2ere1" ;ret_val = nil; EventMachine.stop}
}
body "done processing 1"
end
aget '/2' do
body "done processing 2"
end
end
当我发出以下命令时,它运行良好:
curl http://localhost:3000/2
但是,当我发出以下请求时,它会打印“h2”并且应用程序会静默退出:
curl http://localhost:3000/1
任何帮助将不胜感激。谢谢!