Skip to content

Commit 33d1faf

Browse files
committed
Ensure the order of #close is consistent.
1 parent df4d6d1 commit 33d1faf

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/protocol/http/body/completable.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ def rewind
3333
end
3434

3535
def close(error = nil)
36-
super.tap do
37-
if @callback
38-
@callback.call(error)
39-
@callback = nil
40-
end
36+
if @callback
37+
@callback.call(error)
38+
@callback = nil
4139
end
40+
41+
super
4242
end
4343
end
4444
end

test/protocol/http/body/completable.rb

+14
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,18 @@
9292
expect(completable.rewind).to be == false
9393
end
9494
end
95+
96+
with "#close" do
97+
let(:events) {Array.new}
98+
let(:callback) {Proc.new{events << :close}}
99+
100+
it "invokes callback once" do
101+
completable1 = subject.new(body, proc{events << :close1})
102+
completable2 = subject.new(completable1, proc{events << :close2})
103+
104+
completable2.close
105+
106+
expect(events).to be == [:close2, :close1]
107+
end
108+
end
95109
end

0 commit comments

Comments
 (0)