Created
January 4, 2012 03:22
-
-
Save danielhopkins/1558329 to your computer and use it in GitHub Desktop.
Full chunked sinatra
This file contains hidden or 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
Got this working under jruby 1.6.5 with trinidad as a webserver (webbrick doesn't seem to work) |
This file contains hidden or 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
require 'java' | |
require 'sinatra' | |
get '/stream' do | |
response['Content-Type'] = "application/json" | |
response['Transfer-Encoding'] = 'chunked' | |
Object.new.tap do |o| | |
def o.each | |
loop do | |
yield "{\"currentTime\":\"#{Time.now.strftime '%H:%M:%S'}\"}\n" | |
sleep 2 | |
end | |
end | |
end | |
end |
This file contains hidden or 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
require 'uri' | |
require 'yajl/http_stream' | |
uri = URI.parse("http://localhost:3000/stream") | |
Yajl::HttpStream.get(uri, :symbolize_keys => true) do |hash| | |
puts hash.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment