Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Simple SSE example -- works fine locally, connections never close on Heroku. Running at http://obscure-depths-3413.herokuapp.com/

View Gemfile
1 2 3 4 5 6
source "https://rubygems.org"
ruby '1.9.3'
 
gem 'sinatra'
gem 'thin'
gem 'foreman'
View Gemfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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
View Gemfile
1
web: bundle exec thin -R config.ru start -p $PORT
View Gemfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
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
View Gemfile
1 2 3 4
require "./app"
 
$stdout.sync = true
run MyApp

Ever figure out a solution to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.