Sha256: 8f42949e21faf3ea1a9b659c1239227903822a636ad3e0c5943ec64c092082bc
Contents?: true
Size: 810 Bytes
Versions: 45
Compression:
Stored size: 810 Bytes
Contents
# 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
Version data entries
45 entries across 45 versions & 4 rubygems