require 'sinatra/base'
class Counter < Sinatra::Base
set :server, 'thin' # 'webrick' doesn't work either
get '/' do
haml :index
end
get '/stream' do |out|
out << 'first sentence'
sleep 0.5
out << 'second sentence'
sleep 0.5
end
run!
end
我遵循README文件中的指南,这表明瘦服务器可以正常工作。但它给了我一个空页面,而webrick完全用两个句子来处理页面而没有流效果。
有人能让我知道我哪里做错了吗?
答案 0 :(得分:1)
get '/stream' do
stream do |out|
out << "It's gonna be legen -\n"
sleep 0.5
out << " (wait for it) \n"
sleep 1
out << "- dary!\n"
end
end
通知行:2 stream do |out|