diff --git a/lib/protocol/http/body/completable.rb b/lib/protocol/http/body/completable.rb index 2168cf7..0d83a41 100644 --- a/lib/protocol/http/body/completable.rb +++ b/lib/protocol/http/body/completable.rb @@ -33,12 +33,12 @@ def rewind end def close(error = nil) - super.tap do - if @callback - @callback.call(error) - @callback = nil - end + if @callback + @callback.call(error) + @callback = nil end + + super end end end diff --git a/test/protocol/http/body/completable.rb b/test/protocol/http/body/completable.rb index 092f887..40f2320 100644 --- a/test/protocol/http/body/completable.rb +++ b/test/protocol/http/body/completable.rb @@ -92,4 +92,18 @@ expect(completable.rewind).to be == false end end + + with "#close" do + let(:events) {Array.new} + let(:callback) {Proc.new{events << :close}} + + it "invokes callback once" do + completable1 = subject.new(body, proc{events << :close1}) + completable2 = subject.new(completable1, proc{events << :close2}) + + completable2.close + + expect(events).to be == [:close2, :close1] + end + end end