Skip to content

Instantly share code, notes, and snippets.

@webdev
Last active December 23, 2015 08:09
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 webdev/6606070 to your computer and use it in GitHub Desktop.
Save webdev/6606070 to your computer and use it in GitHub Desktop.
def response(env)
...
notify
end
def notify
env.logger.info "Stream connection opened"
i = 0
# I can stream to response if I do this?? Not sure why is that
# EM.add_periodic_timer(1) do
# env.stream_send("#{i}\n")
# i += 1
# end
EM.run do
redis = Redis.new :driver => :synchrony
puts "connected"
puts redis.get("a")
env.stream_send('setting up redis')
redis.psubscribe("syncs.xyz") do |on|
on.psubscribe do |channel, subscriptions|
puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)"
env.stream_send('test')
end
on.pmessage do |pattern, channel, message|
puts "#{channel}: #{message}"
env.stream_send("#{channel}: #{message}")
end
on.punsubscribe do |channel, subscriptions|
puts "UNsubscribed to ##{channel} (#{subscriptions} subscriptions)"
end
end
end
streaming_response(202, {'X-Stream' => 'Goliath'})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment