Created
January 19, 2013 21:27
-
-
Save ryanb/4575312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd ~/code/rails | |
railties/bin/rails new ~/code/hello --edge | |
cd ~/code/hello | |
echo "gem 'puma'" >> Gemfile | |
bundle | |
rails g controller hello index | |
# fill controller | |
puma | |
# separate tab | |
curl localhost:9292/hello/index | |
# separate tab | |
curl localhost:9292/hello/index # waits until first request finishes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloController < ApplicationController | |
include ActionController::Live | |
def index | |
response.headers["Content-Type"] = "text/event-stream" | |
10.times do |n| | |
response.stream.write "data: #{n}...\n\n" | |
sleep 2 | |
end | |
ensure | |
response.stream.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment