be sure to close the body. also add a config for benchmarking
This commit is contained in:
parent
f8ebf9fbb1
commit
81a049fc71
28
config.ru
Normal file
28
config.ru
Normal file
@ -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 ]
|
||||
}
|
@ -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 }
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Rack
|
||||
class EMStream
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.1.1"
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user