Created
November 2, 2010 17:44
-
-
Save kagminjeong/659992 to your computer and use it in GitHub Desktop.
Sinatra application to test timeout functionality in curb
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
# This Sinatra application must be run with mongrel | |
# or possibly with unicorn for the serve action to work properly. | |
# See http://efreedom.com/Question/1-3669674/Streaming-Data-Sinatra-Rack-Application | |
require 'sinatra' | |
get '/wait/:time' do |time| | |
time = time.to_i | |
sleep(time) | |
"Slept #{time} at #{Time.now}" | |
end | |
# http://efreedom.com/Question/1-3027435/Way-Flush-Html-Wire-Sinatra | |
class Streamer | |
def initialize(time, chunks) | |
@time = time | |
@chunks = chunks | |
end | |
def each | |
@chunks.each do |chunk| | |
sleep(@time) | |
yield chunk | |
end | |
end | |
end | |
get '/serve/:chunk_size/every/:time/for/:count' do |chunk_size, time, count| | |
chunk_size, time, count = chunk_size.to_i, time.to_i, count.to_i | |
chunk = 'x' * chunk_size | |
chunks = [chunk] * count | |
Streamer.new(time, chunks) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment