Sinatra蒸汽助手不起作用

时间:2013-03-01 23:25:15

标签: websocket sinatra

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完全用两个句子来处理页面而没有流效果。

有人能让我知道我哪里做错了吗?

1 个答案:

答案 0 :(得分:1)

摘自Sinatra: The blog

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|