2
我正在开发一个在服务器端使用Sinatra的API。我想要发出一个HTTP请求,但会继续挂起/等待并保持活动状态,直到稍后的事件(另一个事件)导致它在稍后时间以特定的响应值完成为止。如何等待并稍后发送对HTTP请求的响应?
换句话说:
get '/api/foo/:request_identifier' do
# some code here
wait_until_finished params[:request_identifier]
end
# When this URL is visited, the hanging request with the matching
# request identifier will complete, sending "foo response text" to the
# client.
get '/api/bar/:request_identifier' do
make_it_finish params[:request_identifier] "foo response text"
"bar response text"
end
我怎么能实现这一点,还是有得这种效果呢?
我也考虑让客户端不断向服务器轮询已完成请求的请求,但大量的请求可能会导致昂贵的互联网帐单。