Created
February 1, 2014 16:39
-
-
Save Shpigford/8754842 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 LiveController < ApplicationController | |
include ActionController::Live | |
def stream | |
# Set the response header to keep client open | |
response.headers['Content-Type'] = 'text/event-stream' | |
begin | |
100.times { | |
response.stream.write("The temperature is #{ 100*rand} degrees\n") | |
sleep 0.5 | |
} | |
response.stream.write("That's all for now!") | |
rescue IOError | |
# client disconnected | |
ensure | |
response.stream.close | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment