diff --git a/lib/protocol/http/body/completable.rb b/lib/protocol/http/body/completable.rb index a581501..68e152b 100644 --- a/lib/protocol/http/body/completable.rb +++ b/lib/protocol/http/body/completable.rb @@ -25,24 +25,20 @@ def initialize(body, callback) end def finish - if @body - result = super - - @callback.call - - @body = nil - - return result + super.tap do + if @callback + @callback.call + @callback = nil + end end end def close(error = nil) - if @body - super - - @callback.call(error) - - @body = nil + super.tap do + if @callback + @callback.call(error) + @callback = nil + end end end end diff --git a/test/protocol/http/body/completable.rb b/test/protocol/http/body/completable.rb index fdcba8c..17631b6 100644 --- a/test/protocol/http/body/completable.rb +++ b/test/protocol/http/body/completable.rb @@ -5,6 +5,7 @@ require 'protocol/http/body/completable' require 'protocol/http/body/buffered' +require 'protocol/http/request' describe Protocol::HTTP::Body::Completable do let(:body) {Protocol::HTTP::Body::Buffered.new} @@ -76,5 +77,10 @@ completable.finish end end + + it "doesn't break #read after finishing" do + completable.finish + expect(completable.read).to be_nil + end end end