Permalink
Browse files

Simplify BodyProxy#close to avoid horrible loop conditions in streaming

scenarios, and save users from themselves
  • Loading branch information...
raggi committed Oct 1, 2011
1 parent 2bdc3e1 commit 0c26ffeeac330216b66c1e2d621c02943c4787e4
Showing with 6 additions and 11 deletions.
  1. +4 −7 lib/rack/body_proxy.rb
  2. +2 −4 test/spec_body_proxy.rb
View
@@ -9,13 +9,10 @@ def respond_to?(*args)
end
def close
- raise IOError, "closed stream" if @closed
- begin
- @closed = true
- @body.close if @body.respond_to? :close
- ensure
- @block.call
- end
+ return if @closed
+ @closed = true
+ @body.close if @body.respond_to? :close
+ @block.call
end
def closed?
View
@@ -35,10 +35,8 @@
should 'not close more than one time' do
count = 0
proxy = Rack::BodyProxy.new([]) { count += 1; raise "Block invoked more than 1 time!" if count > 1 }
- proxy.close
- lambda {
- proxy.close
- }.should.raise(IOError)
+ 2.times { proxy.close }
+ count.should.equal 1
end
should 'be closed when the callback is triggered' do

1 comment on commit 0c26ffe

@rkh

This comment has been minimized.

Show comment
Hide comment
@rkh

rkh Oct 1, 2011

Member

Can I haz another release?

Member

rkh commented on 0c26ffe Oct 1, 2011

Can I haz another release?

Please sign in to comment.