Skip to content

Instantly share code, notes, and snippets.

@ryanb
Created January 19, 2013 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanb/4575312 to your computer and use it in GitHub Desktop.
Save ryanb/4575312 to your computer and use it in GitHub Desktop.
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
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