I'm trying to implement a small test on rails ActiveController::Live
with Puma server. I started Puma server by rails s puma
, and used curl localhost:3000/messages/events
to do test. However there was a long pause before the data is returned all at once, which was the same as using WEBrick. So Why doesn't the Puma server live stream the results?
class MessagesController < ApplicationController
include ActionController::Live
def index
@messages = Message.all
end
def create
@message = Message.create!(params[:message].permit(:content, :name))
end
def events
3.times do |n|
response.stream.write "#{n}...\n\n"
sleep 2
end
ensure
response.stream.close
end
end