Skip to content

Instantly share code, notes, and snippets.

@fedesoria
Created September 12, 2012 02:28
Show Gist options
  • Save fedesoria/3703846 to your computer and use it in GitHub Desktop.
Save fedesoria/3703846 to your computer and use it in GitHub Desktop.
stream in sinatra
class CheckinServer < Sinatra::Base
include Paperclip::Glue
set :server, :thin
set :views, settings.root + '/../app/views/sinatra'
connections = []
get '/stream', :provides => 'text/event-stream' do
stream :keep_open do |out|
connections << out
out.callback { connections.delete(out) }
end
end
post '/new' do
user = User.find(params[:id])
connections.each { |out| out << "data: #{erb :user, :locals => {:user => user}}\n\n" }
204 # response without entity body
end
def get_connections_size
connections.size
end
end
How can I access get_connections_size from a Rails controller?
Tidy::Application.routes.draw do
mount CheckinServer => '/checkin'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment