diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..80008b7 --- /dev/null +++ b/config.ru @@ -0,0 +1,28 @@ +$: << File.expand_path('../lib', __FILE__) +require 'rack-emstream' + +class Sender + def initialize + @times = 100 + @data = "data" + end + + def each + @times.times { |i| + yield @data + } + end + + def length + @times * @data.length + end +end + +require 'logger' + +use Rack::EMStream +run lambda { |env| + sender = Sender.new + + [ 200, { 'Content-Length' => sender.length.to_s }, sender ] +} diff --git a/lib/rack-emstream.rb b/lib/rack-emstream.rb index 101fecf..a288b40 100644 --- a/lib/rack-emstream.rb +++ b/lib/rack-emstream.rb @@ -22,6 +22,8 @@ module Rack EM.next_tick { env['async.callback'].call [ result[0], result[1], self ] + result[2].close if result[2].respond_to?(:close) + result[2].each { |data| EM.next_tick { @callback.call(data) } } EM.next_tick { succeed } } diff --git a/lib/rack-emstream/version.rb b/lib/rack-emstream/version.rb index 722ab32..3e6a9d2 100644 --- a/lib/rack-emstream/version.rb +++ b/lib/rack-emstream/version.rb @@ -1,5 +1,5 @@ module Rack class EMStream - VERSION = "0.1.0" + VERSION = "0.1.1" end end