Live
默认不使用 SSE
class MyController < ActionController::Base
# 步骤 1
include ActionController::Live
def stream
# 步骤 2
response.headers['Content-Type'] = 'text/event-stream'
100.times {
# 步骤 3 直接使用 response.stream
response.stream.write "hello world\n"
sleep 1
}
ensure
# 步骤 4
response.stream.close
end
end使用 SSE
实例方法
注意事项
最后更新于