Created
June 24, 2013 21:57
-
-
Save mroth/5853993 to your computer and use it in GitHub Desktop.
Simple SSE example -- works fine locally, connections never close on Heroku. Running at http://obscure-depths-3413.herokuapp.com/
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
require 'sinatra/base' | |
class MyApp < Sinatra::Base | |
set :path, '/tmp' | |
set :environment, 'production' | |
def initialize | |
@connections = [] | |
EM::next_tick do | |
EM::add_periodic_timer(1) do | |
@connections.each do |out| | |
out << "connections: " << @connections.count << "\n" | |
end | |
puts "*** connections: #{@connections.count}" | |
end | |
end | |
end | |
get '/' do | |
stream(:keep_open) do |out| | |
@connections << out | |
puts "Stream opened from #{request.ip} (now #{@connections.size} open)" | |
out.callback do | |
@connections.delete(out) | |
puts "Stream closed from #{request.ip} (now #{@connections.size} open)" | |
end | |
end | |
end | |
end |
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
require "./app" | |
$stdout.sync = true | |
run MyApp |
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
source "https://rubygems.org" | |
ruby '1.9.3' | |
gem 'sinatra' | |
gem 'thin' | |
gem 'foreman' |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
daemons (1.1.9) | |
dotenv (0.8.0) | |
eventmachine (1.0.3) | |
foreman (0.63.0) | |
dotenv (>= 0.7) | |
thor (>= 0.13.6) | |
rack (1.5.2) | |
rack-protection (1.5.0) | |
rack | |
sinatra (1.4.3) | |
rack (~> 1.4) | |
rack-protection (~> 1.4) | |
tilt (~> 1.3, >= 1.3.4) | |
thin (1.5.1) | |
daemons (>= 1.0.9) | |
eventmachine (>= 0.12.6) | |
rack (>= 1.0.0) | |
thor (0.18.1) | |
tilt (1.4.1) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
foreman | |
sinatra | |
thin |
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
web: bundle exec thin -R config.ru start -p $PORT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ever figure out a solution to this?