Last active
December 23, 2015 08:09
-
-
Save webdev/6606070 to your computer and use it in GitHub Desktop.
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
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