Browse files

Stream timestamps

  • Loading branch information...
1 parent b6ba6e7 commit a8c41a9a3b93dc8118b6d8e5b9a3c3fe246a72c5 @rwdaigle committed Jun 14, 2011
Showing with 8 additions and 28 deletions.
  1. +1 −0 .rvmrc
  2. +1 −1 Procfile
  3. +6 −27 stream.rb
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2@demo.cedar-streaming --create
View
2 Procfile
@@ -1 +1 @@
-web: bundle exec ruby stream.rb -sv -e production -p $PORT
+web: bundle exec ruby stream.rb -sv -e production -p $PORT
View
33 stream.rb
@@ -3,37 +3,16 @@
Bundler.require
class Stream < Goliath::API
+
def on_close(env)
env.logger.info "Connection closed."
end
-
+
def response(env)
-
- # This timer keeps the connection alive later in the stream when
- # the number generation slows down sufficiently for > 30s response time.
- # Yes, the timer is something like 55s but I like 30s, okay? ;)
- keepalive = EM.add_periodic_timer(29) do
- env.stream_send("Heartbeat.\n")
+ keepalive = EM.add_periodic_timer(1) do
+ env.stream_send("#{Time.now.strftime("%a, %e %b %Y %H:%M:%S")}\n")
end
-
- EM.defer do
- i = 0
- n, m = 0, 1
- while true
- env.stream_send("#{i}: #{n}\n")
- n, m = m, n + m
- i += 1
- end
- end
-
- # The below cuts off the connection at some point if this is desired.
- # EM.add_timer(30) do
- # keepalive.cancel
- #
- # env.stream_send("End of stream.")
- # env.stream_close
- # end
-
+
[200, {'Content-Type' => 'text/plain'}, Goliath::Response::STREAMING]
end
-end
+end

0 comments on commit a8c41a9

Please sign in to comment.